Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstable tests #8

Merged
merged 4 commits into from
Nov 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test: deps

.PHONY: testacc
testacc: deps
TEST_ACC=1 go test -count=1 ./...
TEST_ACC=1 go test -count=1 -failfast ./...

.PHONY: check
check: lint vet test build
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ services:
environment:
CGO_ENABLED: 0 # disable cgo for go test
LOCALSTACK_ENDPOINT: "http://localstack:4566"
# Use the same filesystem to avoid a checksum mismatch error
# or a file busy error caused by asynchronous IO.
TF_PLUGIN_CACHE_DIR: "/tmp/plugin-cache"
depends_on:
- localstack

Expand Down
8 changes: 8 additions & 0 deletions tfexec/test_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,14 @@ func SetupTestAccWithApply(t *testing.T, source string) TerraformCLI {
t.Fatalf("failed to run terraform apply: %s", err)
}

// destroy resources after each test not to have any state.
t.Cleanup(func() {
err := tf.Destroy(ctx, "", "-input=false", "-no-color", "-auto-approve")
if err != nil {
t.Fatalf("failed to run terraform destroy: %s", err)
}
})

return tf
}

Expand Down
5 changes: 5 additions & 0 deletions tfmigrate/state_import_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,9 @@ resource "aws_iam_user" "baz" {
if err != nil {
t.Fatalf("failed to run migrator plan: %s", err)
}

err = m.Apply(ctx)
if err != nil {
t.Fatalf("failed to run migrator apply: %s", err)
}
}