Skip to content

Commit

Permalink
Add tests for parse plan file
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Apr 28, 2022
1 parent a7ee94e commit 6258cc7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
48 changes: 48 additions & 0 deletions migration/plan_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package migration

import (
"os"
"testing"
)

func TestNewPlan(t *testing.T) {
cases := []struct {
desc string
planFile string
ok bool
}{
{
desc: "valid",
planFile: "test-fixtures/import_simple.tfplan.json",
ok: true,
},
{
desc: "invalid",
planFile: "test-fixtures/invalid.tfplan.json",
ok: false,
},
{
desc: "unknown format version",
planFile: "test-fixtures/unknown_format_version.tfplan.json",
ok: false,
},
}

for _, tc := range cases {
t.Run(tc.desc, func(t *testing.T) {
planJSON, err := os.ReadFile(tc.planFile)
if err != nil {
t.Fatalf("failed to read file: %s", err)
}

got, err := NewPlan(planJSON)
if tc.ok && err != nil {
t.Fatalf("unexpected err = %s", err)
}

if !tc.ok && err == nil {
t.Fatalf("expected to return an error, but no error, got: %#v", got)
}
})
}
}
1 change: 1 addition & 0 deletions migration/test-fixtures/invalid.tfplan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "invalid":
1 change: 1 addition & 0 deletions migration/test-fixtures/unknown_format_version.tfplan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "format_version": "0" }

0 comments on commit 6258cc7

Please sign in to comment.