Skip to content

Commit

Permalink
Merge pull request #14 from jasondborneman/tester/wildcardFiltering
Browse files Browse the repository at this point in the history
Review Feedback 1
  • Loading branch information
jasondborneman authored Jan 12, 2024
2 parents 2b0ae31 + 2af660f commit a4fc896
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
2 changes: 2 additions & 0 deletions example/weather/services/tester/design/design.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var _ = Service("tester", func() {
})
Description("The Weather System Tester Service is used to manage the integration testing of the weater system")
Error("include_exclude_both", ErrorResult, "Cannot specify both include and exclude")
Error("wildcard_compile_error", ErrorResult, "Wildcard glob did not compile")

Method("test_all", func() {
Description("Runs all tests in the iam system")
Expand All @@ -26,6 +27,7 @@ var _ = Service("tester", func() {
GRPC(func() {
Response(CodeOK)
Response("include_exclude_both", CodeInvalidArgument)
Response("wildcard_compile_error", CodeInvalidArgument)
})
})

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions example/weather/services/tester/gen/tester/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions example/weather/services/tester/gen/tester/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 20 additions & 7 deletions example/weather/services/tester/run_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ func recoverFromTestPanic(ctx context.Context, testName string, testCollection *

// Filters a testMap based on a test name that is a glob string
// using standard wildcards https://tldp.org/LDP/GNU-Linux-Tools-Summary/html/x11655.htm
func matchTestFilter(ctx context.Context, test string, testMap map[string]func(context.Context, *TestCollection)) (bool, []func(context.Context, *TestCollection)) {
func matchTestFilter(ctx context.Context, test string, testMap map[string]func(context.Context, *TestCollection)) ([]func(context.Context, *TestCollection), error) {
match := false
testMatches := []func(context.Context, *TestCollection){}
var testMatches []func(context.Context, *TestCollection)
var g glob.Glob
g = glob.MustCompile(test)
g, err := glob.Compile(test)
if err != nil {
_ = logError(ctx, err)
err = errors.New(fmt.Sprintf("wildcard glob [%s] did not compile: %v", test, err))
return testMatches, err
}
i := 0
for testName, _ := range testMap {
match = g.Match(testName)
Expand All @@ -92,7 +97,7 @@ func matchTestFilter(ctx context.Context, test string, testMap map[string]func(c
}
i++
}
return match, testMatches
return testMatches, nil
}

// Runs the tests from the testmap and handles filtering/exclusion of tests
Expand All @@ -116,8 +121,11 @@ func (svc *Service) runTests(ctx context.Context, p *gentester.TesterPayload, te
if testFunc, ok := testMap[test]; ok {
testsToRun[test] = testFunc
} else { // Test didn't match exactly, so we're gonna try for a wildcard match
findByWildcard, testFuncs := matchTestFilter(ctx, test, testMap)
if findByWildcard {
testFuncs, err := matchTestFilter(ctx, test, testMap)
if err != nil {
return nil, gentester.MakeWildcardCompileError(err)
}
if len(testFuncs) > 0 {
for i, testFunc := range testFuncs {
testsToRun[fmt.Sprintf("%s_%d", test, i)] = testFunc
}
Expand All @@ -132,7 +140,12 @@ func (svc *Service) runTests(ctx context.Context, p *gentester.TesterPayload, te
wildcardMatch := false
for _, excludeTest := range p.Exclude {
var g glob.Glob
g = glob.MustCompile(excludeTest)
g, err := glob.Compile(excludeTest)
if err != nil {
_ = logError(ctx, err)
err = errors.New(fmt.Sprintf("wildcard glob [%s] did not compile: %v", excludeTest, err))
return nil, gentester.MakeWildcardCompileError(err)
}
wildcardMatch = wildcardMatch || g.Match(testName)
}
if !wildcardMatch {
Expand Down

0 comments on commit a4fc896

Please sign in to comment.