...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package resourcefixture
16
17 import (
18 "fmt"
19 "testing"
20
21 "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test"
22 testconstants "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/constants"
23 )
24
25 type ShouldRunFunc func(fixture ResourceFixture) bool
26 type TestCaseFunc func(t *testing.T, fixture ResourceFixture)
27
28 func RunTests(t *testing.T, shouldRun ShouldRunFunc, testCaseFunc TestCaseFunc) {
29 testCases := Load(t)
30 for _, tc := range testCases {
31 if !shouldRun(tc) {
32 continue
33 }
34 runTestCase(t, tc, testCaseFunc)
35 }
36 }
37
38 func RunSpecificTests(t *testing.T, fixtures []ResourceFixture, testCaseFunc TestCaseFunc) {
39 for _, f := range fixtures {
40 runTestCase(t, f, testCaseFunc)
41 }
42 }
43
44 func runTestCase(t *testing.T, fixture ResourceFixture, testCaseFunc TestCaseFunc) {
45 testName := FormatTestName(fixture)
46 if test.StringMatchesRegexList(t, testconstants.TestNameRegexesToSkip, testName) {
47 return
48 }
49 t.Run(FormatTestName(fixture), func(t *testing.T) {
50 t.Parallel()
51 testCaseFunc(t, fixture)
52
53 })
54 }
55
56 func FormatTestName(tc ResourceFixture) string {
57 return fmt.Sprintf("%v-%v", string(tc.Type), tc.Name)
58 }
59
View as plain text