diff --git a/internal/refactoring/move_execute.go b/internal/refactoring/move_execute.go index 1fc60f85f..26eef65c0 100644 --- a/internal/refactoring/move_execute.go +++ b/internal/refactoring/move_execute.go @@ -28,6 +28,8 @@ type MoveResult struct { // ApplyMoves expects exclusive access to the given state while it's running. // Don't read or write any part of the state structure until ApplyMoves returns. func ApplyMoves(stmts []MoveStatement, state *states.State) map[addrs.UniqueKey]MoveResult { + results := make(map[addrs.UniqueKey]MoveResult) + // The methodology here is to construct a small graph of all of the move // statements where the edges represent where a particular statement // is either chained from or nested inside the effect of another statement. @@ -40,7 +42,7 @@ func ApplyMoves(stmts []MoveStatement, state *states.State) map[addrs.UniqueKey] // at all. The separate validation step should detect this and return // an error. if len(g.Cycles()) != 0 { - return nil + return results } // The starting nodes are the ones that don't depend on any other nodes. @@ -51,7 +53,6 @@ func ApplyMoves(stmts []MoveStatement, state *states.State) map[addrs.UniqueKey] } } - results := make(map[addrs.UniqueKey]MoveResult) g.DepthFirstWalk(startNodes, func(v dag.Vertex, depth int) error { stmt := v.(*MoveStatement) diff --git a/internal/refactoring/move_execute_test.go b/internal/refactoring/move_execute_test.go index eed56e911..4041bedff 100644 --- a/internal/refactoring/move_execute_test.go +++ b/internal/refactoring/move_execute_test.go @@ -15,10 +15,6 @@ import ( ) func TestApplyMoves(t *testing.T) { - // TODO: Renable this once we're ready to implement the intended behaviors - // it is describing. - t.Skip("ApplyMoves is not yet fully implemented") - providerAddr := addrs.AbsProviderConfig{ Module: addrs.RootModule, Provider: addrs.MustParseProviderSourceString("example.com/foo/bar"), @@ -48,6 +44,8 @@ func TestApplyMoves(t *testing.T) { }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance), } + emptyResults := map[addrs.UniqueKey]MoveResult{} + tests := map[string]struct { Stmts []MoveStatement State *states.State @@ -58,7 +56,7 @@ func TestApplyMoves(t *testing.T) { "no moves and empty state": { []MoveStatement{}, states.NewState(), - nil, + emptyResults, nil, }, "no moves": { @@ -73,7 +71,7 @@ func TestApplyMoves(t *testing.T) { providerAddr, ) }), - nil, + emptyResults, []string{ `foo.from`, }, @@ -98,7 +96,7 @@ func TestApplyMoves(t *testing.T) { To: rootNoKeyResourceAddr[1], }, rootNoKeyResourceAddr[1].UniqueKey(): { - From: rootNoKeyResourceAddr[1], + From: rootNoKeyResourceAddr[0], To: rootNoKeyResourceAddr[1], }, }, @@ -121,11 +119,11 @@ func TestApplyMoves(t *testing.T) { ) }), map[addrs.UniqueKey]MoveResult{ - rootNoKeyResourceAddr[0].UniqueKey(): { + rootIntKeyResourceAddr[0].UniqueKey(): { From: rootIntKeyResourceAddr[0], To: rootIntKeyResourceAddr[1], }, - rootNoKeyResourceAddr[1].UniqueKey(): { + rootIntKeyResourceAddr[1].UniqueKey(): { From: rootIntKeyResourceAddr[0], To: rootIntKeyResourceAddr[1], },