Skip to content

Commit

Permalink
Add acceptance test for import
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Jul 27, 2020
1 parent dc279c3 commit aff51df
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tfexec/terraform_import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,37 @@ func TestTerraformCLIImport(t *testing.T) {
})
}
}

func TestAccTerraformCLIImport(t *testing.T) {
if !isAcceptanceTestEnabled() {
t.Skip("skip acceptance tests")
}

source := `
resource "random_string" "foo" {
length = 4
}
`
e := setupTestAcc(t, source)
terraformCLI := NewTerraformCLI(e)

err := terraformCLI.Init(context.Background(), "", "-input=false", "-no-color")
if err != nil {
t.Fatalf("failed to run terraform init: %s", err)
}

state, err := terraformCLI.Import(context.Background(), nil, "random_string.foo", "test", "-input=false", "-no-color")
if err != nil {
t.Fatalf("failed to run terraform import: %s", err)
}

got, err := terraformCLI.StateList(context.Background(), state, nil)
if err != nil {
t.Fatalf("failed to run terraform state list: %s", err)
}

want := []string{"random_string.foo"}
if !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want: %v", got, want)
}
}

0 comments on commit aff51df

Please sign in to comment.