Skip to content

Commit

Permalink
Merge pull request #17 from jasondborneman/bugfixes011624
Browse files Browse the repository at this point in the history
simplify how `TestAll` works
  • Loading branch information
jasondborneman authored Jan 16, 2024
2 parents 8901f30 + 8a697d4 commit ecf2768
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
38 changes: 15 additions & 23 deletions example/weather/services/tester/test_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,30 +18,27 @@ func (t *TestCollection) AppendTestResult(tr ...*gentester.TestResult) {
t.Results = append(t.Results, tr...)
}

var filteringPayload = &gentester.TesterPayload{}

// Runs all test collections EXCEPT smoke tests (those are in their own collections as well)
func (svc *Service) TestAll(ctx context.Context, p *gentester.TesterPayload) (res *gentester.TestResults, err error) {
retval := gentester.TestResults{}
filteringPayload = p
forecasterResults, err := svc.TestForecaster(ctx)

// Forecaster tests
forecasterCollection := TestCollection{
Name: "Forecaster Tests",
}
forecasterResults, err := svc.runTests(ctx, p, &forecasterCollection, svc.forecasterTestMap, false)
if err != nil {
_ = logError(ctx, err)
// filteringPayload needs reset as TestAll calls the OTHER test methods
// and we only want a filteringPayload if it came via TestAll.
// if the other test methods are called directly (e.g. TestForecaster)
// it doesn't accept a gentester.TesterPayload
filteringPayload = &gentester.TesterPayload{}
return nil, err
}
locatorResults, err := svc.TestLocator(ctx)

// Locator tests
locatorCollection := TestCollection{
Name: "Locator Tests",
}
locatorResults, err := svc.runTests(ctx, p, &locatorCollection, svc.locatorTestMap, true)
if err != nil {
_ = logError(ctx, err)
// filteringPayload needs reset as TestAll calls the OTHER test methods
// and we only want a filteringPayload if it came via TestAll.
// if the other test methods are called directly (e.g. TestForecaster)
// it doesn't accept a gentester.TesterPayload
filteringPayload = &gentester.TesterPayload{}
return nil, err
}

Expand All @@ -56,11 +53,6 @@ func (svc *Service) TestAll(ctx context.Context, p *gentester.TesterPayload) (re
retval.FailCount += r.FailCount
}

// filteringPayload needs reset as TestAll calls the OTHER test methods
// and we only want a filteringPayload if it came via TestAll.
// if the other test methods are called directly (e.g. TestForecaster)
// it doesn't accept a gentester.TesterPayload
filteringPayload = &gentester.TesterPayload{}
return &retval, nil
}

Expand All @@ -70,7 +62,7 @@ func (svc *Service) TestSmoke(ctx context.Context) (res *gentester.TestResults,
smokeCollection := TestCollection{
Name: "Smoke Tests",
}
return svc.runTests(ctx, filteringPayload, &smokeCollection, svc.smokeTestMap, false)
return svc.runTests(ctx, nil, &smokeCollection, svc.smokeTestMap, false)
}

// Runs the Forecaster Service tests as a collection in parallel
Expand All @@ -79,7 +71,7 @@ func (svc *Service) TestForecaster(ctx context.Context) (res *gentester.TestResu
forecasterCollection := TestCollection{
Name: "Forecaster Tests",
}
return svc.runTests(ctx, filteringPayload, &forecasterCollection, svc.forecasterTestMap, false)
return svc.runTests(ctx, nil, &forecasterCollection, svc.forecasterTestMap, false)
}

// Runs the Locator Service tests as a collection synchronously
Expand All @@ -88,5 +80,5 @@ func (svc *Service) TestLocator(ctx context.Context) (res *gentester.TestResults
locatorCollection := TestCollection{
Name: "Locator Tests",
}
return svc.runTests(ctx, filteringPayload, &locatorCollection, svc.locatorTestMap, true)
return svc.runTests(ctx, nil, &locatorCollection, svc.locatorTestMap, true)
}
2 changes: 2 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaL
github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-openapi/swag v0.22.4 h1:QLMzNJnMGPRNDCbySlcj1x01tzU8/9LTTL9hZZZogBU=
github.com/go-openapi/swag v0.22.4/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14=
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
Expand Down Expand Up @@ -575,6 +576,7 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
Expand Down

0 comments on commit ecf2768

Please sign in to comment.