mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 08:51:02 -06:00
0b1dbf31a3
Currently Terraform is leaking goroutines and with that memory. I know strictly speaking this maybe isn’t a real concern for Terraform as it’s mostly used as a short running command line executable. But there are a few of us out there that are using Terraform in some long running processes and then this starts to become a problem. Next to that it’s of course good programming practise to clean up resources when they're not needed anymore. So even for the standard command line use case, this seems an improvement in resource management. Personally I see no downsides as the primary connection to the plugin is kept alive (the plugin is not killed) and only unused connections that will never be used again are closed to free up any related goroutines and memory.
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package terraform
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestEvalInitProvisioner_impl(t *testing.T) {
|
|
var _ EvalNode = new(EvalInitProvisioner)
|
|
}
|
|
|
|
func TestEvalInitProvisioner(t *testing.T) {
|
|
n := &EvalInitProvisioner{Name: "foo"}
|
|
provisioner := &MockResourceProvisioner{}
|
|
ctx := &MockEvalContext{InitProvisionerProvisioner: provisioner}
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !ctx.InitProvisionerCalled {
|
|
t.Fatal("should be called")
|
|
}
|
|
if ctx.InitProvisionerName != "foo" {
|
|
t.Fatalf("bad: %#v", ctx.InitProvisionerName)
|
|
}
|
|
}
|
|
|
|
func TestEvalCloseProvisioner(t *testing.T) {
|
|
n := &EvalCloseProvisioner{Name: "foo"}
|
|
provisioner := &MockResourceProvisioner{}
|
|
ctx := &MockEvalContext{CloseProvisionerProvisioner: provisioner}
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !ctx.CloseProvisionerCalled {
|
|
t.Fatal("should be called")
|
|
}
|
|
if ctx.CloseProvisionerName != "foo" {
|
|
t.Fatalf("bad: %#v", ctx.CloseProvisionerName)
|
|
}
|
|
}
|
|
|
|
func TestEvalGetProvisioner_impl(t *testing.T) {
|
|
var _ EvalNode = new(EvalGetProvisioner)
|
|
}
|
|
|
|
func TestEvalGetProvisioner(t *testing.T) {
|
|
var actual ResourceProvisioner
|
|
n := &EvalGetProvisioner{Name: "foo", Output: &actual}
|
|
provisioner := &MockResourceProvisioner{}
|
|
ctx := &MockEvalContext{ProvisionerProvisioner: provisioner}
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
if actual != provisioner {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
|
|
if !ctx.ProvisionerCalled {
|
|
t.Fatal("should be called")
|
|
}
|
|
if ctx.ProvisionerName != "foo" {
|
|
t.Fatalf("bad: %#v", ctx.ProvisionerName)
|
|
}
|
|
}
|