-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add acceptance test for TestAccMultiStateMvAction
- Loading branch information
1 parent
3ad4053
commit abc738d
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package tfmigrate | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/minamijoyo/tfmigrate/tfexec" | ||
) | ||
|
||
func TestAccMultiStateMvAction(t *testing.T) { | ||
tfexec.SkipUnlessAcceptanceTestEnabled(t) | ||
ctx := context.Background() | ||
|
||
// setup the initial files and states | ||
fromBackend := tfexec.GetTestAccBackendS3Config(t.Name() + "/fromDir") | ||
fromSource := ` | ||
resource "null_resource" "foo" {} | ||
resource "null_resource" "bar" {} | ||
resource "null_resource" "baz" {} | ||
` | ||
fromWorkspace := "default" | ||
fromTf := tfexec.SetupTestAccWithApply(t, fromWorkspace, fromBackend+fromSource) | ||
|
||
toBackend := tfexec.GetTestAccBackendS3Config(t.Name() + "/toDir") | ||
toSource := ` | ||
resource "null_resource" "qux" {} | ||
` | ||
toWorkspace := "default" | ||
toTf := tfexec.SetupTestAccWithApply(t, toWorkspace, toBackend+toSource) | ||
|
||
// update terraform resource files for migration | ||
fromUpdatedSource := ` | ||
resource "null_resource" "baz" {} | ||
` | ||
tfexec.UpdateTestAccSource(t, fromTf, fromBackend+fromUpdatedSource) | ||
|
||
toUpdatedSource := ` | ||
resource "null_resource" "foo" {} | ||
resource "null_resource" "bar2" {} | ||
resource "null_resource" "qux" {} | ||
` | ||
tfexec.UpdateTestAccSource(t, toTf, toBackend+toUpdatedSource) | ||
|
||
fromChanged, err := fromTf.PlanHasChange(ctx, nil) | ||
if err != nil { | ||
t.Fatalf("failed to run PlanHasChange in fromDir: %s", err) | ||
} | ||
if !fromChanged { | ||
t.Fatalf("expect to have changes in fromDir") | ||
} | ||
|
||
toChanged, err := toTf.PlanHasChange(ctx, nil) | ||
if err != nil { | ||
t.Fatalf("failed to run PlanHasChange in toDir: %s", err) | ||
} | ||
if !toChanged { | ||
t.Fatalf("expect to have changes in toDir") | ||
} | ||
|
||
// perform state migration | ||
actions := []MultiStateAction{ | ||
NewMultiStateMvAction("null_resource.foo", "null_resource.foo"), | ||
NewMultiStateMvAction("null_resource.bar", "null_resource.bar2"), | ||
} | ||
o := &MigratorOption{} | ||
force := false | ||
m := NewMultiStateMigrator(fromTf.Dir(), toTf.Dir(), fromWorkspace, toWorkspace, actions, o, force) | ||
err = m.Plan(ctx) | ||
if err != nil { | ||
t.Fatalf("failed to run migrator plan: %s", err) | ||
} | ||
} |