mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-01 11:47:07 -06:00
67d441b131
* remove leftover debug line * terraform: refactor ProviderEvalTree This PR refactors the ProviderEvalTree by folding the entire tree into straight-through code in NodeApplyableProvider Execute (formally EvalTree). The EvalConfigProvider functions were refactored into NodeApplyableProvider functions (since that was the only place they were used). I also removed the unused node_provider_disabled code. * revert removal of graphNodeCloseProvider EvalTree, replace with Execute
118 lines
3.3 KiB
Go
118 lines
3.3 KiB
Go
package terraform
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
"github.com/hashicorp/terraform/configs"
|
|
"github.com/zclconf/go-cty/cty"
|
|
)
|
|
|
|
func TestNodeApplyableProviderExecute(t *testing.T) {
|
|
config := &configs.Provider{
|
|
Name: "foo",
|
|
Config: configs.SynthBody("", map[string]cty.Value{
|
|
"test_string": cty.StringVal("hello"),
|
|
}),
|
|
}
|
|
provider := mockProviderWithConfigSchema(simpleTestSchema())
|
|
providerAddr := addrs.AbsProviderConfig{
|
|
Module: addrs.RootModule,
|
|
Provider: addrs.NewDefaultProvider("foo"),
|
|
}
|
|
|
|
n := &NodeApplyableProvider{&NodeAbstractProvider{
|
|
Addr: providerAddr,
|
|
Config: config,
|
|
}}
|
|
|
|
ctx := &MockEvalContext{ProviderProvider: provider}
|
|
ctx.installSimpleEval()
|
|
if err := n.Execute(ctx, walkApply); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !ctx.ConfigureProviderCalled {
|
|
t.Fatal("should be called")
|
|
}
|
|
|
|
gotObj := ctx.ConfigureProviderConfig
|
|
if !gotObj.Type().HasAttribute("test_string") {
|
|
t.Fatal("configuration object does not have \"test_string\" attribute")
|
|
}
|
|
if got, want := gotObj.GetAttr("test_string"), cty.StringVal("hello"); !got.RawEquals(want) {
|
|
t.Errorf("wrong configuration value\ngot: %#v\nwant: %#v", got, want)
|
|
}
|
|
}
|
|
|
|
func TestNodeApplyableProviderExecute_unknownImport(t *testing.T) {
|
|
config := &configs.Provider{
|
|
Name: "foo",
|
|
Config: configs.SynthBody("", map[string]cty.Value{
|
|
"test_string": cty.UnknownVal(cty.String),
|
|
}),
|
|
}
|
|
provider := mockProviderWithConfigSchema(simpleTestSchema())
|
|
providerAddr := addrs.AbsProviderConfig{
|
|
Module: addrs.RootModule,
|
|
Provider: addrs.NewDefaultProvider("foo"),
|
|
}
|
|
n := &NodeApplyableProvider{&NodeAbstractProvider{
|
|
Addr: providerAddr,
|
|
Config: config,
|
|
}}
|
|
|
|
ctx := &MockEvalContext{ProviderProvider: provider}
|
|
ctx.installSimpleEval()
|
|
|
|
err := n.Execute(ctx, walkImport)
|
|
if err == nil {
|
|
t.Fatal("expected error, got success")
|
|
}
|
|
|
|
detail := `Invalid provider configuration: The configuration for provider["registry.terraform.io/hashicorp/foo"] depends on values that cannot be determined until apply.`
|
|
if got, want := err.Error(), detail; got != want {
|
|
t.Errorf("wrong diagnostic detail\n got: %q\nwant: %q", got, want)
|
|
}
|
|
|
|
if ctx.ConfigureProviderCalled {
|
|
t.Fatal("should not be called")
|
|
}
|
|
}
|
|
|
|
func TestNodeApplyableProviderExecute_unknownApply(t *testing.T) {
|
|
config := &configs.Provider{
|
|
Name: "foo",
|
|
Config: configs.SynthBody("", map[string]cty.Value{
|
|
"test_string": cty.UnknownVal(cty.String),
|
|
}),
|
|
}
|
|
provider := mockProviderWithConfigSchema(simpleTestSchema())
|
|
providerAddr := addrs.AbsProviderConfig{
|
|
Module: addrs.RootModule,
|
|
Provider: addrs.NewDefaultProvider("foo"),
|
|
}
|
|
n := &NodeApplyableProvider{&NodeAbstractProvider{
|
|
Addr: providerAddr,
|
|
Config: config,
|
|
}}
|
|
ctx := &MockEvalContext{ProviderProvider: provider}
|
|
ctx.installSimpleEval()
|
|
|
|
if err := n.Execute(ctx, walkApply); err != nil {
|
|
t.Fatalf("err: %s", err)
|
|
}
|
|
|
|
if !ctx.ConfigureProviderCalled {
|
|
t.Fatal("should be called")
|
|
}
|
|
|
|
gotObj := ctx.ConfigureProviderConfig
|
|
if !gotObj.Type().HasAttribute("test_string") {
|
|
t.Fatal("configuration object does not have \"test_string\" attribute")
|
|
}
|
|
if got, want := gotObj.GetAttr("test_string"), cty.UnknownVal(cty.String); !got.RawEquals(want) {
|
|
t.Errorf("wrong configuration value\ngot: %#v\nwant: %#v", got, want)
|
|
}
|
|
}
|