diff --git a/helper/resource/testing.go b/helper/resource/testing.go index af3d2dda4..b97673fdf 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -418,6 +418,17 @@ func LogOutput(t TestT) (logOutput io.Writer, err error) { return } +// ParallelTest performs an acceptance test on a resource, allowing concurrency +// with other ParallelTest. +// +// Tests will fail if they do not properly handle conditions to allow multiple +// tests to occur against the same resource or service (e.g. random naming). +// All other requirements of the Test function also apply to this function. +func ParallelTest(t TestT, c TestCase) { + t.Parallel() + Test(t, c) +} + // Test performs an acceptance test on a resource. // // Tests are not run unless an environmental variable "TF_ACC" is @@ -1128,6 +1139,7 @@ type TestT interface { Fatal(args ...interface{}) Skip(args ...interface{}) Name() string + Parallel() } // This is set to true by unit tests to alter some behavior diff --git a/helper/resource/testing_test.go b/helper/resource/testing_test.go index e9c55fb57..9146b4d79 100644 --- a/helper/resource/testing_test.go +++ b/helper/resource/testing_test.go @@ -45,6 +45,15 @@ func (p *resetProvider) TestReset() error { return p.TestResetError } +func TestParallelTest(t *testing.T) { + mt := new(mockT) + ParallelTest(mt, TestCase{}) + + if !mt.ParallelCalled { + t.Fatal("Parallel() not called") + } +} + func TestTest(t *testing.T) { mp := &resetProvider{ MockResourceProvider: testProvider(), @@ -112,6 +121,9 @@ func TestTest(t *testing.T) { if mt.failed() { t.Fatalf("test failed: %s", mt.failMessage()) } + if mt.ParallelCalled { + t.Fatal("Parallel() called") + } if !checkStep { t.Fatal("didn't call check for step") } @@ -692,12 +704,13 @@ func TestComposeTestCheckFunc(t *testing.T) { // mockT implements TestT for testing type mockT struct { - ErrorCalled bool - ErrorArgs []interface{} - FatalCalled bool - FatalArgs []interface{} - SkipCalled bool - SkipArgs []interface{} + ErrorCalled bool + ErrorArgs []interface{} + FatalCalled bool + FatalArgs []interface{} + ParallelCalled bool + SkipCalled bool + SkipArgs []interface{} f bool } @@ -714,6 +727,10 @@ func (t *mockT) Fatal(args ...interface{}) { t.f = true } +func (t *mockT) Parallel() { + t.ParallelCalled = true +} + func (t *mockT) Skip(args ...interface{}) { t.SkipCalled = true t.SkipArgs = args