Skip to content

Commit 2305fe3

Browse files
authored
Merge pull request #47 from gruntwork-io/feature/add-test-suite-base
add TestSuiteBase struct
2 parents 571f8ed + 1cdc309 commit 2305fe3

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

terratest.go

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,47 @@
55
//
66
// It is meant to be used by authors of Terraform templates to systematically validate that their terraform templates
77
// work as expected across a range of inputs such as a randomly selected AWS Region.
8-
package terratest
8+
package terratest
9+
10+
import (
11+
"log"
12+
"testing"
13+
)
14+
15+
// This is intended to be used as part of setting up a suite of tests for a particular module. This is particularly
16+
// useful when you want to run apply/destroy once, but want to run many assert statements to verify state is as expected.
17+
//
18+
// Example:
19+
//
20+
// func TestFooSuite(t *testing.T) {
21+
// testSuite := TestSuiteBase{}
22+
//
23+
// testSuite.logger = terralog.NewLogger("TestFooSuiteSuite")
24+
// testSuite.resourceCollection = resources.CreateBaseRandomResourceCollection(t, "")
25+
//
26+
// defer tearDownSuite(t, &testSuite)
27+
//
28+
// _, err = terratest.Apply(testSuite.terratestOptions)
29+
// if err != nil {
30+
// t.Fatalf("Unexpected error when applying terraform templates: %v", err)
31+
// }
32+
//
33+
// t.Run("foo tests", func(t *testing.T) {
34+
// t.Run("fooTest1", WrapTestCase(testOne, &testSuite))
35+
// t.Run("fooTest2", WrapTestCase(testTwo, &testSuite))
36+
// t.Run("fooTest3", WrapTestCase(testThree, &testSuite))
37+
// })
38+
// }
39+
//
40+
type TestSuiteBase struct {
41+
logger *log.Logger
42+
resourceCollection *RandomResourceCollection
43+
terratestOptions *TerratestOptions
44+
terraformOutput string
45+
}
46+
47+
func WrapTestCase(testCase func(t *testing.T, testSuite *TestSuiteBase), testSuite *TestSuiteBase) func(t *testing.T) {
48+
return func(t *testing.T) {
49+
testCase(t, testSuite)
50+
}
51+
}

0 commit comments

Comments
 (0)