Skip to content
This repository was archived by the owner on Mar 11, 2021. It is now read-only.

Commit f303764

Browse files
committed
Parametrize pact broker password, make publishing part of the consumer tests.
1 parent abc66b7 commit f303764

6 files changed

Lines changed: 21 additions & 7 deletions

File tree

.make/test.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ test-integration-no-coverage: prebuild-check migrate-database $(SOURCES)
197197
test-contract-auth-consumers:
198198
cd $(CONTRACT_TESTS)/auth && \
199199
PACT_DIR=$(CONTRACT_TESTS)/pacts \
200+
PACT_VERSION=$(PACT_VERSION) \
201+
PACT_BROKER_URL=$(PACT_BROKER_URL) \
200202
./consumer-contracts.sh
201203

202204
.PHONY: test-contract-auth-publish

test/contracts/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
**/*log
22
**/*logs
3-
**/*pacts
3+
**/*pacts
4+
.password

test/contracts/auth/auth_api_user.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ type MissingToken struct {
7373
} `json:"errors"`
7474
}
7575

76-
const JWSRegex = "[a-zA-Z0-9\\-_]+?\\.?[a-zA-Z0-9\\-_]+?\\.?([a-zA-Z0-9\\-_]+)?"
76+
const jwsRegex = "[a-zA-Z0-9\\-_]+?\\.?[a-zA-Z0-9\\-_]+?\\.?([a-zA-Z0-9\\-_]+)?"
77+
const userNameRegex = "[a-zA-Z\\-0-9]+"
7778

7879
// AuthAPIUserByNameConsumer defines contract of /api/users?filter[username]=<user_name> endpoint
7980
func AuthAPIUserByNameConsumer(t *testing.T, pact *dsl.Pact) {
@@ -106,7 +107,7 @@ func AuthAPIUserByNameConsumer(t *testing.T, pact *dsl.Pact) {
106107
Query: dsl.MapMatcher{
107108
"filter[username]": dsl.Term(
108109
userName,
109-
".*",
110+
userNameRegex,
110111
),
111112
},
112113
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/json")},
@@ -152,7 +153,7 @@ func AuthAPIUserByIDConsumer(t *testing.T, pact *dsl.Pact) {
152153
Method: "GET",
153154
Path: dsl.Term(
154155
fmt.Sprintf("/api/users/%s", userID),
155-
"/api/users/.*",
156+
fmt.Sprintf("/api/users/%s", userNameRegex),
156157
),
157158
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/json")},
158159
}).
@@ -203,7 +204,7 @@ func AuthAPIUserInvalidToken(t *testing.T, pact *dsl.Pact) {
203204
"Content-Type": dsl.String("application/json"),
204205
"Authorization": dsl.Term(
205206
fmt.Sprintf("Bearer %s", invalidToken),
206-
fmt.Sprintf("^Bearer %s$", JWSRegex),
207+
fmt.Sprintf("^Bearer %s$", jwsRegex),
207208
),
208209
},
209210
}).

test/contracts/auth/consumer-contracts.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@
44

55
# run test
66
go test -v -run 'Test*'
7+
TEST_EXIT=$?
8+
9+
if [ "$TEST_EXIT" == "0" ]; then
10+
./publish-contracts.sh
11+
fi

test/contracts/auth/contract_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func TestAuthAPI(t *testing.T) {
1414
pact := &dsl.Pact{
1515
Consumer: os.Getenv("PACT_CONSUMER"),
1616
Provider: os.Getenv("PACT_PROVIDER"),
17+
PactDir: os.Getenv("PACT_DIR"),
1718
Host: "localhost",
1819
PactFileWriteMode: "merge",
1920
}

test/contracts/auth/setenv.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@ set -a
66
GOPATH="$GOPATH:$(pwd)"
77

88
# A directory to save pact files
9-
PACT_DIR="${PACT_DIR:-pacts}"
9+
PACT_DIR="${PACT_DIR:-$(pwd)/pacts}"
1010
PACT_CONSUMER="${PACT_CONSUMER:-Fabric8TenantService}"
1111
PACT_PROVIDER="${PACT_PROVIDER:-Fabric8AuthService}"
1212

1313
PACT_BROKER_URL="${PACT_BROKER_URL:-http://pact-broker-pact-broker.193b.starter-ca-central-1.openshiftapps.com}"
1414
PACT_BROKER_USERNAME="${PACT_BROKER_USERNAME:-pact_broker}"
15-
PACT_BROKER_PASSWORD="${PACT_BROKER_PASSWORD:-}"
15+
if [ -z "$PACT_BROKER_PASSWORD" ]; then
16+
if [ -f .password ]; then
17+
PACT_BROKER_PASSWORD="$(cat .password)"
18+
fi
19+
fi
1620

1721
PACT_PROVIDER_BASE_URL="${PACT_PROVIDER_BASE_URL:-https://auth.openshift.io}"

0 commit comments

Comments
 (0)