Skip to content

Commit

Permalink
tests: run tests grouped by GVK group
Browse files Browse the repository at this point in the history
This will enable us to split the execution by service.
  • Loading branch information
justinsb committed Feb 6, 2024
1 parent 6d8cd9e commit fbc6f75
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion pkg/test/resourcefixture/test_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,46 @@ package resourcefixture
import (
"context"
"fmt"
"strings"
"testing"

"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test"
testconstants "github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test/constants"
"k8s.io/apimachinery/pkg/util/sets"
)

type ShouldRunFunc func(fixture ResourceFixture) bool
type TestCaseFunc func(ctx context.Context, t *testing.T, fixture ResourceFixture)

func RunTests(ctx context.Context, t *testing.T, shouldRun ShouldRunFunc, testCaseFunc TestCaseFunc) {
testCases := Load(t)

var filtered []ResourceFixture
for _, tc := range testCases {
if !shouldRun(tc) {
continue
}
runTestCase(ctx, t, tc, testCaseFunc)
filtered = append(filtered, tc)
}

// Run tests grouped by the group of the GVK
groups := sets.NewString()
for _, tc := range filtered {
groups.Insert(tc.GVK.Group)
}

for _, group := range groups.List() {
group := group
groupTestName := strings.TrimSuffix(group, ".cnrm.cloud.google.com")
t.Run(groupTestName, func(t *testing.T) {
t.Parallel()
for _, tc := range filtered {
if tc.GVK.Group != group {
continue
}
runTestCase(ctx, t, tc, testCaseFunc)
}
})
}
}

Expand Down

0 comments on commit fbc6f75

Please sign in to comment.