From 789317dc05157a3d8d8b76aaf88aa9f8d82a3053 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 4 Aug 2021 09:36:22 -0400 Subject: [PATCH] additional test --- internal/refactoring/move_execute_test.go | 40 ++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/internal/refactoring/move_execute_test.go b/internal/refactoring/move_execute_test.go index 4041bedff..5943445cb 100644 --- a/internal/refactoring/move_execute_test.go +++ b/internal/refactoring/move_execute_test.go @@ -30,6 +30,11 @@ func TestApplyMoves(t *testing.T) { Type: "foo", Name: "to", }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), + addrs.Resource{ + Mode: addrs.ManagedResourceMode, + Type: "foo", + Name: "mid", + }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), } rootIntKeyResourceAddr := [...]addrs.AbsResourceInstance{ addrs.Resource{ @@ -132,13 +137,46 @@ func TestApplyMoves(t *testing.T) { `foo.to[0]`, }, }, + "chained move of whole singleton resource": { + []MoveStatement{ + testMoveStatement(t, "", "foo.from", "foo.mid"), + testMoveStatement(t, "", "foo.mid", "foo.to"), + }, + states.BuildState(func(s *states.SyncState) { + s.SetResourceInstanceCurrent( + rootNoKeyResourceAddr[0], + &states.ResourceInstanceObjectSrc{ + Status: states.ObjectReady, + AttrsJSON: []byte(`{}`), + }, + providerAddr, + ) + }), + map[addrs.UniqueKey]MoveResult{ + rootNoKeyResourceAddr[0].UniqueKey(): { + From: rootNoKeyResourceAddr[0], + To: rootNoKeyResourceAddr[2], + }, + rootNoKeyResourceAddr[2].UniqueKey(): { + From: rootNoKeyResourceAddr[2], + To: rootNoKeyResourceAddr[1], + }, + rootNoKeyResourceAddr[1].UniqueKey(): { + From: rootNoKeyResourceAddr[2], + To: rootNoKeyResourceAddr[1], + }, + }, + []string{ + `foo.to`, + }, + }, } for name, test := range tests { t.Run(name, func(t *testing.T) { var stmtsBuf strings.Builder for _, stmt := range test.Stmts { - fmt.Fprintf(&stmtsBuf, "- from: %s\n to: %s", stmt.From, stmt.To) + fmt.Fprintf(&stmtsBuf, "- from: %s\n to: %s\n", stmt.From, stmt.To) } t.Logf("move statements:\n%s", stmtsBuf.String())