Skip to content

Commit

Permalink
Test state list after apply and destroy
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Jul 27, 2020
1 parent dea9fac commit dc279c3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tfexec/terraform_apply_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tfexec

import (
"context"
"reflect"
"regexp"
"testing"
)
Expand Down Expand Up @@ -138,4 +139,14 @@ func TestAccTerraformCLIApply(t *testing.T) {
if err != nil {
t.Fatalf("failed to run terraform apply: %s", err)
}

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

want := []string{"null_resource.foo"}
if !reflect.DeepEqual(got, want) {
t.Errorf("got: %v, want: %v", got, want)
}
}
9 changes: 9 additions & 0 deletions tfexec/terraform_destroy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,13 @@ func TestAccTerraformCLIDestroy(t *testing.T) {
if err != nil {
t.Fatalf("failed to run terraform destroy: %s", err)
}

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

if len(got) != 0 {
t.Errorf("expected no resources, but got: %v", got)
}
}

0 comments on commit dc279c3

Please sign in to comment.