Skip to content

Commit

Permalink
skip samples flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Aug 19, 2024
1 parent 04a4757 commit 39d7428
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion config/tests/samples/create/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func init() {
// regexes to be used to match test names. The "test name" in this case
// corresponds to the directory name of the sample YAMLs.
flag.StringVar(&runTestsRegex, "run-tests", "", "run only the tests whose names match the given regex")
flag.StringVar(&skipTestsRegex, "skip-tests", "", "skip the tests whose names match the given regex, even those that match the run-tests regex")
// cleanup-resources allows you to disable the cleanup of resources created during testing. This can be useful for debugging test failures.
// The default value is true.
//
Expand All @@ -52,6 +53,7 @@ func init() {

var (
runTestsRegex string
skipTestsRegex string
cleanupResources bool
mgr manager.Manager
// this manager is only used to get the rest.Config from the test framework
Expand Down Expand Up @@ -233,7 +235,19 @@ func TestAll(t *testing.T) {
project := testgcp.GetDefaultProject(t)

setup()
samples := LoadMatchingSamples(t, regexp.MustCompile(runTestsRegex), project)
allSamples := LoadMatchingSamples(t, regexp.MustCompile(runTestsRegex), project)
skippedSamples := ListMatchingSamples(t, regexp.MustCompile(skipTestsRegex))

var samples []Sample
skippedMap := make(map[string]bool)
for _, skipped := range skippedSamples {
skippedMap[skipped.Name] = true
}
for _, sample := range allSamples {
if _, exists := skippedMap[sample.Name]; !exists {
samples = append(samples, sample)
}
}
if len(samples) == 0 {
t.Fatalf("No tests to run for pattern %s", runTestsRegex)
}
Expand Down

0 comments on commit 39d7428

Please sign in to comment.