Skip to content

Commit

Permalink
Add acceptance test for state rm
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Jul 31, 2020
1 parent 82e5902 commit f126c68
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tfexec/terraform_state_rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,44 @@ func TestTerraformCLIStateRm(t *testing.T) {
})
}
}

func TestAccTerraformCLIStateRm(t *testing.T) {
SkipUnlessAcceptanceTestEnabled(t)

source := `
resource "null_resource" "foo" {}
resource "null_resource" "bar" {}
`
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)
}

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

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

updatedState, err := terraformCLI.StateRm(context.Background(), state, []string{"null_resource.foo"})
if err != nil {
t.Fatalf("failed to run terraform state rm: %s", err)
}

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

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

0 comments on commit f126c68

Please sign in to comment.