From df36a03be10a460eb84477e7bccb576c0869d196 Mon Sep 17 00:00:00 2001 From: Alisdair McDiarmid Date: Wed, 5 Jan 2022 12:29:20 -0500 Subject: [PATCH] states: Add failing test for ordered dependencies --- internal/states/instance_object_test.go | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 internal/states/instance_object_test.go diff --git a/internal/states/instance_object_test.go b/internal/states/instance_object_test.go new file mode 100644 index 000000000..f8be9743e --- /dev/null +++ b/internal/states/instance_object_test.go @@ -0,0 +1,37 @@ +package states + +import ( + "testing" + + "github.com/google/go-cmp/cmp" + "github.com/hashicorp/terraform/internal/addrs" + "github.com/zclconf/go-cty/cty" +) + +func TestResourceInstanceObject_encode(t *testing.T) { + value := cty.ObjectVal(map[string]cty.Value{ + "foo": cty.True, + }) + deps := []addrs.ConfigResource{ + addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "honk"), + addrs.RootModule.Child("child").Resource(addrs.ManagedResourceMode, "test", "flub"), + addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "boop"), + } + wantDeps := []addrs.ConfigResource{ + addrs.RootModule.Child("child").Resource(addrs.ManagedResourceMode, "test", "flub"), + addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "boop"), + addrs.RootModule.Resource(addrs.ManagedResourceMode, "test", "honk"), + } + rio := &ResourceInstanceObject{ + Value: value, + Status: ObjectPlanned, + Dependencies: deps, + } + rios, err := rio.Encode(value.Type(), 0) + if err != nil { + t.Fatalf("unexpected error: %s", err) + } + if diff := cmp.Diff(wantDeps, rios.Dependencies); diff != "" { + t.Errorf("wrong result for deps\n%s", diff) + } +}