-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example
tester
service to show API Integration Testing of a Goa…
… System (#331) * initial commit * Empty-Commit * add readme file (still need to fill out) * tester readme update * Trying out a workflow to run integration tests against local binaries * Add proto install to /example/weather/scripts/setup * fix integration.yaml * disable mono on ubuntu * move mono stop * Try to find out what's running on 8084 * Trying to disable mono? * trying to stop mono 2 * add a sleep after stop/disable? * add some echo * see if stop/disable mono fails * add back in || true, change front ports to see if this even works at all * oops forgot to change int test port * try no send to dev null? * sleep before testing * take out netstat * sleep longer? give time for docker to do work to get grafana? * remove dev>null again... :\ * sleep 60 :( * Implement review comment changes * Fix runTests check for filtering if * Empty-Commit * try starting each service individually, check fo rmono * just KILL mono? * back to 8084, check all ports * fix typo * add flag to turn off grafana for services (for CI testing) * clean up integration.yaml script * review fixes * Get Stack Trace to Err Log on Panic * small fixes for style * protoc -> 25.1, better wait in integration.yaml * Add synchronous testing feature * Make one of the synchronous as an example * move func maps to service definition
- Loading branch information
1 parent
c78642b
commit 1b6ed57
Showing
57 changed files
with
6,010 additions
and
473 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
name: Integration Tests | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
|
||
jobs: | ||
integration-tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-go@v4 | ||
with: | ||
go-version: "1.21" | ||
- name: tests | ||
run: | | ||
check_service_health() { | ||
local health_url="$1" | ||
local start_time=$(date +%s) | ||
while : ; do | ||
if curl -s --fail "$health_url" > /dev/null; then | ||
echo "Service is up!" | ||
return 0 | ||
fi | ||
local current_time=$(date +%s) | ||
if (( current_time - start_time >= 5 )); then | ||
echo "Timed out waiting for service to be up." | ||
return 1 | ||
fi | ||
sleep 0.2 | ||
done | ||
} | ||
echo "stop/disable/kill mono" | ||
sudo systemctl stop mono-xsp4.service || true | ||
sudo systemctl disable mono-xsp4.service || true | ||
sudo pkill mono || true | ||
echo "change to weather example directory" | ||
cd example/weather | ||
echo "run setup script" | ||
./scripts/setup | ||
echo "run server" | ||
./bin/forecaster -monitoring-enabled=false & | ||
./bin/locator -monitoring-enabled=false & | ||
./bin/tester -monitoring-enabled=false & | ||
./bin/front -monitoring-enabled=false & | ||
check_service_health "http://localhost:8081/healthz" & | ||
check_service_health "http://localhost:8083/healthz" & | ||
check_service_health "http://localhost:8091/healthz" & | ||
check_service_health "http://localhost:8085/healthz" & | ||
wait -n | ||
echo "-----RUN TESTS-----" | ||
results=$(curl -X POST http://localhost:8084/tester/smoke) | ||
echo "-----RESULTS-----" | ||
echo $results | ||
echo "----------" | ||
if [ $(echo $results | jq '.fail_count') -gt 0 ]; | ||
then | ||
echo "Test errors found." | ||
exit 1 | ||
else | ||
echo "Tests passed." | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
forecaster: bin/forecaster | ||
locator: bin/locator | ||
front: bin/front | ||
tester: bin/tester |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
example/weather/services/front/clients/tester/client.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package tester | ||
|
||
import ( | ||
"context" | ||
|
||
"goa.design/clue/debug" | ||
"goa.design/clue/log" | ||
goa "goa.design/goa/v3/pkg" | ||
"google.golang.org/grpc" | ||
|
||
genfront "goa.design/clue/example/weather/services/front/gen/front" | ||
genclient "goa.design/clue/example/weather/services/tester/gen/grpc/tester/client" | ||
gentester "goa.design/clue/example/weather/services/tester/gen/tester" | ||
) | ||
|
||
type ( | ||
Client interface { | ||
// Runs ALL API Integration Tests from the Tester service, allowing for filtering on included or excluded tests | ||
TestAll(ctx context.Context, included, excluded []string) (*genfront.TestResults, error) | ||
// Runs API Integration Tests' Smoke Tests ONLY from the Tester service | ||
TestSmoke(ctx context.Context) (*genfront.TestResults, error) | ||
} | ||
|
||
TestAllPayload struct { | ||
Include []string | ||
Exclude []string | ||
} | ||
|
||
client struct { | ||
testSmoke goa.Endpoint | ||
testAll goa.Endpoint | ||
} | ||
) | ||
|
||
// Creates a new client for the Tester service. | ||
func New(cc *grpc.ClientConn) Client { | ||
c := genclient.NewClient(cc, grpc.WaitForReady(true)) | ||
return &client{ | ||
debug.LogPayloads(debug.WithClient())(c.TestSmoke()), | ||
debug.LogPayloads(debug.WithClient())(c.TestAll()), | ||
} | ||
} | ||
|
||
// TestSmoke runs the Smoke collection as defined in func_map.go of the tester service | ||
func (c *client) TestSmoke(ctx context.Context) (*genfront.TestResults, error) { | ||
res, err := c.testSmoke(ctx, nil) | ||
if err != nil { | ||
log.Errorf(ctx, err, "failed to run smoke tests: %s", err) | ||
return nil, err | ||
} | ||
return testerTestResultsToFrontTestResults(res.(*gentester.TestResults)), nil | ||
} | ||
|
||
// TestAll runs all tests in all collections. Obeys include and exclude filters. | ||
// include and exclude are mutually exclusive and cannot be used together (400 error, bad request) | ||
func (c *client) TestAll(ctx context.Context, included, excluded []string) (*genfront.TestResults, error) { | ||
gtPayload := &gentester.TesterPayload{ | ||
Include: included, | ||
Exclude: excluded, | ||
} | ||
res, err := c.testAll(ctx, gtPayload) | ||
if err != nil { | ||
log.Errorf(ctx, err, "failed to run all tests: %s", err) | ||
return nil, err | ||
} | ||
return testerTestResultsToFrontTestResults(res.(*gentester.TestResults)), nil | ||
} | ||
|
||
func testerTestResultsToFrontTestResults(testResults *gentester.TestResults) *genfront.TestResults { | ||
var res = &genfront.TestResults{} | ||
if testResults != nil { | ||
res.Collections = testerTestCollectionsArrToFrontTestCollectionsArr(testResults.Collections) | ||
res.Duration = testResults.Duration | ||
res.PassCount = testResults.PassCount | ||
res.FailCount = testResults.FailCount | ||
} | ||
return res | ||
} | ||
|
||
func testerTestCollectionsArrToFrontTestCollectionsArr(testCollection []*gentester.TestCollection) []*genfront.TestCollection { | ||
var res []*genfront.TestCollection | ||
for _, v := range testCollection { | ||
res = append(res, testerTestCollectionToFrontTestCollection(v)) | ||
} | ||
return res | ||
} | ||
|
||
func testerTestCollectionToFrontTestCollection(testCollection *gentester.TestCollection) *genfront.TestCollection { | ||
var res = &genfront.TestCollection{} | ||
if testCollection != nil { | ||
res.Name = testCollection.Name | ||
res.Results = testerTestResultsArrToFrontTestResultsArr(testCollection.Results) | ||
res.Duration = testCollection.Duration | ||
res.PassCount = testCollection.PassCount | ||
res.FailCount = testCollection.FailCount | ||
} | ||
return res | ||
} | ||
|
||
func testerTestResultsArrToFrontTestResultsArr(testResults []*gentester.TestResult) []*genfront.TestResult { | ||
var res []*genfront.TestResult | ||
for _, v := range testResults { | ||
res = append(res, (*genfront.TestResult)(v)) | ||
} | ||
return res | ||
} |
72 changes: 72 additions & 0 deletions
72
example/weather/services/front/clients/tester/mocks/client.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.