This repository has been archived by the owner on Mar 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add consumer side of WIT+Auth contract tests. (#2393)
This PR adds consumer side of the contract tests for the [WIT service](https://github.com/fabric8-services/fabric8-wit) consuming [Auth service](https://github.com/fabric8-services/fabric8-auth) API endpoints. CICO job: [openshiftio/openshiftio-cico-jobs#940](openshiftio/openshiftio-cico-jobs#940) The provider side (Auth service) of the contract tests is covered by [fabric8-services/fabric8-auth#711](fabric8-services/fabric8-auth#711) WorkItem: https://openshift.io/openshiftio/Openshift_io/plan/detail/1329
- Loading branch information
Showing
15 changed files
with
647 additions
and
12 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
. cico_setup.sh | ||
|
||
CICO_RUN="${CICO_RUN:-true}" | ||
if [ "$CICO_RUN" == "true" ]; then | ||
load_jenkins_vars; | ||
if [ -e "jenkins-env.json" ]; then | ||
eval "$(./env-toolkit load -f jenkins-env.json --regex 'PACT_*')" | ||
fi | ||
install_deps; | ||
fi | ||
make docker-start | ||
make docker-build | ||
|
||
DOCKER_CONTAINER_NAME="${BUILD_TAG:-fabric8-wit-local-build}" | ||
|
||
#Ensure Pact CLI is installed | ||
cmd="curl -L -s https://github.com/pact-foundation/pact-ruby-standalone/releases/download/v1.63.0/pact-1.63.0-linux-x86_64.tar.gz -o /tmp/pact-cli.tar.gz \ | ||
&& mkdir -p /tmp/pact \ | ||
&& tar -xf /tmp/pact-cli.tar.gz --directory /tmp \ | ||
&& rm -vf /tmp/pact-cli.tar.gz" | ||
docker exec -t "$DOCKER_CONTAINER_NAME" /bin/bash -ec "$cmd" | ||
|
||
# Run the contract tests | ||
cmd="PATH=\$PATH:/tmp/pact/bin make test-contracts-consumer-no-coverage" | ||
docker exec -t "$DOCKER_CONTAINER_NAME" /bin/bash -ec "$cmd" | ||
|
||
# Publish the generated Pact files to Pact broker. | ||
cmd="PATH=\$PATH:/tmp/pact/bin make publish-contract-testing-pacts-to-broker" | ||
docker exec -t \ | ||
-e PACT_BROKER_URL=$PACT_BROKER_URL \ | ||
-e PACT_BROKER_USERNAME=$PACT_BROKER_USERNAME \ | ||
-e PACT_BROKER_PASSWORD=$PACT_BROKER_PASSWORD \ | ||
-e PACT_VERSION=${PACT_VERSION:-PR-commit} \ | ||
-e PACT_TAGS=${PACT_TAGS:-PR-testing} \ | ||
"$DOCKER_CONTAINER_NAME" /bin/bash -ec "$cmd" |
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,4 @@ | ||
# For API contract testing | ||
pacts | ||
output | ||
**/*/logs |
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,36 @@ | ||
package fabric8auth_test | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
|
||
"github.com/fabric8-services/fabric8-wit/test/contracts" | ||
"github.com/fabric8-services/fabric8-wit/test/contracts/consumer" | ||
"github.com/pact-foundation/pact-go/dsl" | ||
) | ||
|
||
// AuthAPIStatus defines contract of /api/status endpoint | ||
func AuthAPIStatus(t *testing.T, pact *dsl.Pact) { | ||
|
||
log.Printf("Invoking AuthAPIStatus now\n") | ||
|
||
// Set up our expected interactions. | ||
pact. | ||
AddInteraction(). | ||
Given("Auth service is up and running."). | ||
UponReceiving("A request to get status"). | ||
WithRequest(dsl.Request{ | ||
Method: "GET", | ||
Path: dsl.String("/api/status"), | ||
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/json")}, | ||
}). | ||
WillRespondWith(dsl.Response{ | ||
Status: 200, | ||
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/vnd.status+json")}, | ||
Body: dsl.Match(APIStatusMessage{}), | ||
}) | ||
|
||
// Verify | ||
err := pact.Verify(consumer_test.SimpleGetInteraction(pact, "/api/status")) | ||
contracts_test.CheckErrorAndCleanPact(t, pact, err) //workaround for https://github.com/pact-foundation/pact-go/issues/108 | ||
} |
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,35 @@ | ||
package fabric8auth_test | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
|
||
"github.com/fabric8-services/fabric8-wit/test/contracts" | ||
"github.com/fabric8-services/fabric8-wit/test/contracts/consumer" | ||
"github.com/pact-foundation/pact-go/dsl" | ||
) | ||
|
||
// AuthAPITokenKeys defines contract of /api/status endpoint | ||
func AuthAPITokenKeys(t *testing.T, pact *dsl.Pact) { | ||
|
||
log.Printf("Invoking AuthAPITokenKeys now\n") | ||
|
||
// Set up our expected interactions. | ||
pact. | ||
AddInteraction(). | ||
Given("Auth service is up and running."). | ||
UponReceiving("A request to get public keys"). | ||
WithRequest(dsl.Request{ | ||
Method: "GET", | ||
Path: dsl.String("/api/token/keys"), | ||
}). | ||
WillRespondWith(dsl.Response{ | ||
Status: 200, | ||
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/vnd.publickeys+json")}, | ||
Body: dsl.Match(TokenKeys{}), | ||
}) | ||
|
||
// Verify | ||
err := pact.Verify(consumer_test.SimpleGetInteraction(pact, "/api/token/keys")) | ||
contracts_test.CheckErrorAndCleanPact(t, pact, err) //workaround for https://github.com/pact-foundation/pact-go/issues/108 | ||
} |
Oops, something went wrong.