opentofu/terraform/transform_diff_test.go
Kristin Laemmert 47a16b0937
addrs: embed Provider in AbsProviderConfig instead of Type
a large refactor to addrs.AbsProviderConfig, embedding the addrs.Provider instead of a Type string. I've added and updated tests, added some Legacy functions to support older state formats and shims, and added a normalization step when reading v4 (current) state files (not the added tests under states/statefile/roundtrip which work with both current and legacy-style AbsProviderConfig strings).

The remaining 'fixme' and 'todo' comments are mostly going to be addressed in a subsequent PR and involve looking up a given local provider config's FQN. This is fine for now as we are only working with default assumption.
2020-02-13 15:32:58 -05:00

73 lines
1.5 KiB
Go

package terraform
import (
"strings"
"testing"
"github.com/zclconf/go-cty/cty"
"github.com/hashicorp/terraform/addrs"
"github.com/hashicorp/terraform/plans"
)
func TestDiffTransformer_nilDiff(t *testing.T) {
g := Graph{Path: addrs.RootModuleInstance}
tf := &DiffTransformer{}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
if len(g.Vertices()) > 0 {
t.Fatal("graph should be empty")
}
}
func TestDiffTransformer(t *testing.T) {
g := Graph{Path: addrs.RootModuleInstance}
beforeVal, err := plans.NewDynamicValue(cty.StringVal(""), cty.String)
if err != nil {
t.Fatal(err)
}
afterVal, err := plans.NewDynamicValue(cty.StringVal(""), cty.String)
if err != nil {
t.Fatal(err)
}
tf := &DiffTransformer{
Changes: &plans.Changes{
Resources: []*plans.ResourceInstanceChangeSrc{
{
Addr: addrs.Resource{
Mode: addrs.ManagedResourceMode,
Type: "aws_instance",
Name: "foo",
}.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance),
ProviderAddr: addrs.AbsProviderConfig{
Provider: addrs.NewLegacyProvider("aws"),
Module: addrs.RootModuleInstance,
},
ChangeSrc: plans.ChangeSrc{
Action: plans.Update,
Before: beforeVal,
After: afterVal,
},
},
},
},
}
if err := tf.Transform(&g); err != nil {
t.Fatalf("err: %s", err)
}
actual := strings.TrimSpace(g.String())
expected := strings.TrimSpace(testTransformDiffBasicStr)
if actual != expected {
t.Fatalf("bad:\n\n%s", actual)
}
}
const testTransformDiffBasicStr = `
aws_instance.foo
`