Skip to content

Commit

Permalink
Add acceptance test for TestAccMultiStateMvAction
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Dec 26, 2022
1 parent 3ad4053 commit abc738d
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions tfmigrate/multi_state_mv_action_test.go
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)
}
}

0 comments on commit abc738d

Please sign in to comment.