mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -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.
154 lines
3.4 KiB
Go
154 lines
3.4 KiB
Go
package terraform
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
func TestEvalBuildProviderConfig_impl(t *testing.T) {
|
|
var _ EvalNode = new(EvalBuildProviderConfig)
|
|
}
|
|
|
|
func TestEvalBuildProviderConfig(t *testing.T) {
|
|
config := testResourceConfig(t, map[string]interface{}{})
|
|
provider := "foo"
|
|
|
|
n := &EvalBuildProviderConfig{
|
|
Provider: provider,
|
|
Config: &config,
|
|
Output: &config,
|
|
}
|
|
|
|
ctx := &MockEvalContext{
|
|
ParentProviderConfigConfig: testResourceConfig(t, map[string]interface{}{
|
|
"foo": "bar",
|
|
}),
|
|
ProviderInputConfig: map[string]interface{}{
|
|
"bar": "baz",
|
|
},
|
|
}
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
expected := map[string]interface{}{
|
|
"foo": "bar",
|
|
"bar": "baz",
|
|
}
|
|
if !reflect.DeepEqual(config.Raw, expected) {
|
|
t.Fatalf("bad: %#v", config.Raw)
|
|
}
|
|
}
|
|
|
|
func TestEvalBuildProviderConfig_parentPriority(t *testing.T) {
|
|
config := testResourceConfig(t, map[string]interface{}{})
|
|
provider := "foo"
|
|
|
|
n := &EvalBuildProviderConfig{
|
|
Provider: provider,
|
|
Config: &config,
|
|
Output: &config,
|
|
}
|
|
|
|
ctx := &MockEvalContext{
|
|
ParentProviderConfigConfig: testResourceConfig(t, map[string]interface{}{
|
|
"foo": "bar",
|
|
}),
|
|
ProviderInputConfig: map[string]interface{}{
|
|
"foo": "baz",
|
|
},
|
|
}
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
expected := map[string]interface{}{
|
|
"foo": "bar",
|
|
}
|
|
if !reflect.DeepEqual(config.Raw, expected) {
|
|
t.Fatalf("bad: %#v", config.Raw)
|
|
}
|
|
}
|
|
|
|
func TestEvalConfigProvider_impl(t *testing.T) {
|
|
var _ EvalNode = new(EvalConfigProvider)
|
|
}
|
|
|
|
func TestEvalConfigProvider(t *testing.T) {
|
|
config := testResourceConfig(t, map[string]interface{}{})
|
|
provider := &MockResourceProvider{}
|
|
n := &EvalConfigProvider{Config: &config}
|
|
|
|
ctx := &MockEvalContext{ProviderProvider: provider}
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !ctx.ConfigureProviderCalled {
|
|
t.Fatal("should be called")
|
|
}
|
|
if !reflect.DeepEqual(ctx.ConfigureProviderConfig, config) {
|
|
t.Fatalf("bad: %#v", ctx.ConfigureProviderConfig)
|
|
}
|
|
}
|
|
|
|
func TestEvalInitProvider_impl(t *testing.T) {
|
|
var _ EvalNode = new(EvalInitProvider)
|
|
}
|
|
|
|
func TestEvalInitProvider(t *testing.T) {
|
|
n := &EvalInitProvider{Name: "foo"}
|
|
provider := &MockResourceProvider{}
|
|
ctx := &MockEvalContext{InitProviderProvider: provider}
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !ctx.InitProviderCalled {
|
|
t.Fatal("should be called")
|
|
}
|
|
if ctx.InitProviderName != "foo" {
|
|
t.Fatalf("bad: %#v", ctx.InitProviderName)
|
|
}
|
|
}
|
|
|
|
func TestEvalCloseProvider(t *testing.T) {
|
|
n := &EvalCloseProvider{Name: "foo"}
|
|
provider := &MockResourceProvider{}
|
|
ctx := &MockEvalContext{CloseProviderProvider: provider}
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !ctx.CloseProviderCalled {
|
|
t.Fatal("should be called")
|
|
}
|
|
if ctx.CloseProviderName != "foo" {
|
|
t.Fatalf("bad: %#v", ctx.CloseProviderName)
|
|
}
|
|
}
|
|
|
|
func TestEvalGetProvider_impl(t *testing.T) {
|
|
var _ EvalNode = new(EvalGetProvider)
|
|
}
|
|
|
|
func TestEvalGetProvider(t *testing.T) {
|
|
var actual ResourceProvider
|
|
n := &EvalGetProvider{Name: "foo", Output: &actual}
|
|
provider := &MockResourceProvider{}
|
|
ctx := &MockEvalContext{ProviderProvider: provider}
|
|
if _, err := n.Eval(ctx); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
if actual != provider {
|
|
t.Fatalf("bad: %#v", actual)
|
|
}
|
|
|
|
if !ctx.ProviderCalled {
|
|
t.Fatal("should be called")
|
|
}
|
|
if ctx.ProviderName != "foo" {
|
|
t.Fatalf("bad: %#v", ctx.ProviderName)
|
|
}
|
|
}
|