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

Commit

Permalink
contract-tests: Implement consumer of fabric8auth service.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmacik committed Jan 14, 2019
1 parent d363afe commit 2465e9f
Show file tree
Hide file tree
Showing 11 changed files with 404 additions and 784 deletions.
25 changes: 12 additions & 13 deletions .make/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,20 @@ test-integration-benchmark: prebuild-check migrate-database $(SOURCES)
$(eval TEST_PACKAGES:=$(shell go list ./... | grep -v $(ALL_PKGS_EXCLUDE_PATTERN)))
F8_DEVELOPER_MODE_ENABLED=1 F8_RESOURCE_DATABASE=1 F8_RESOURCE_UNIT_TEST=0 F8_LOG_LEVEL=$(F8_LOG_LEVEL) go test -run=^$$ -bench=. -cpu 1,2,4 -test.benchmem $(GO_TEST_VERBOSITY_FLAG) $(TEST_PACKAGES) | grep -E "Bench|allocs"

.PHONY: test-contracts-no-coverage
## Runs the contract tests WITHOUT producing coverage files for each package.
## Make sure you ran "make integration-test-env-prepare" before you run this target.
test-contracts-no-coverage: prebuild-check migrate-database $(SOURCES)
.PHONY: test-contracts-consumer-no-coverage
## Runs the consumer side of contract tests WITHOUT producing coverage files for each package.
## and publish generated Pact file (the contract) to the Pact broker.
## The following env variables needs to be set in environment:
## - Pact broker for storing pact files
## PACT_BROKER_URL
## PACT_BROKER_USERNAME
## PACT_BROKER_PASSWORD
test-contracts-consumer-no-coverage:
$(call log-info,"Running test: $@")
$(eval TEST_PACKAGES:=$(shell go list ./... | grep contracts | grep 'consumer\|provider'))
$(eval TEST_PACKAGES:=$(shell go list ./... | grep -e 'contracts/consumer'))
PACT_DIR=$(PWD)/test/contracts/pacts \
PACT_CONSUMER=Fabric8WitConsumer \
PACT_PROVIDER=Fabric8Wit \
PACT_VERSION=1.0.0 \
PACT_PROVIDER_BASE_URL=http://localhost:8080 \
PACT_PROVIDER_AUTH_BASE_URL=http://localhost:8089 \
OSIO_USERNAME="$(OSIO_USERNAME)" \
OSIO_PASSWORD="$(OSIO_PASSWORD)" \
go test -count=1 $(GO_TEST_VERBOSITY_FLAG) $(TEST_PACKAGES)
PACT_VERSION="latest" \
go test $(GO_TEST_VERBOSITY_FLAG) -count=1 $(TEST_PACKAGES)

.PHONY: test-remote
## Runs the remote tests and produces coverage files for each package.
Expand Down
7 changes: 2 additions & 5 deletions Gopkg.lock

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

82 changes: 0 additions & 82 deletions test/contracts/consumer/api_space.go

This file was deleted.

63 changes: 0 additions & 63 deletions test/contracts/consumer/consumer_test.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package consumer
package fabric8auth

import (
"fmt"
"log"
"net/http"
"testing"

"github.com/fabric8-services/fabric8-wit/test/contracts"
"github.com/fabric8-services/fabric8-auth/test/contracts/model"
"github.com/pact-foundation/pact-go/dsl"
)

// APIStatus defines contract of /api/status endpoint
func APIStatus(t *testing.T, pact *dsl.Pact) {
// AuthAPIStatus defines contract of /api/status endpoint
func AuthAPIStatus(t *testing.T, pact *dsl.Pact) {

log.Printf("Invoking APIStatus now\n")
log.Printf("Invoking AuthAPIStatus now\n")

// Pass in test case
var test = func() error {
Expand All @@ -35,7 +35,7 @@ func APIStatus(t *testing.T, pact *dsl.Pact) {
// Set up our expected interactions.
pact.
AddInteraction().
Given("WIT service is up and running.").
Given("Auth service is up and running.").
UponReceiving("A request to get status").
WithRequest(dsl.Request{
Method: "GET",
Expand All @@ -45,7 +45,7 @@ func APIStatus(t *testing.T, pact *dsl.Pact) {
WillRespondWith(dsl.Response{
Status: 200,
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/vnd.status+json")},
Body: dsl.Match(contracts.APIStatusResponse{}),
Body: dsl.Match(model.APIStatusMessage{}),
})

// Verify
Expand Down
55 changes: 55 additions & 0 deletions test/contracts/consumer/fabric8auth/api_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package fabric8auth

import (
"fmt"
"log"
"net/http"
"testing"

"github.com/fabric8-services/fabric8-auth/test/contracts/model"
"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")

// Pass in test case
var test = func() error {
u := fmt.Sprintf("http://localhost:%d/api/token/keys", pact.Server.Port)
req, err := http.NewRequest("GET", u, nil)

req.Header.Set("Accept", "application/json")
if err != nil {
return err
}

_, err = http.DefaultClient.Do(req)
if err != nil {
return err
}
return err
}

// 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"),
Headers: dsl.MapMatcher{"Accept": dsl.String("application/json")},
}).
WillRespondWith(dsl.Response{
Status: 200,
Headers: dsl.MapMatcher{"Content-Type": dsl.String("application/vnd.publickeys+json")},
Body: dsl.Match(model.TokenKeys{}),
})

// Verify
if err := pact.Verify(test); err != nil {
log.Fatalf("Error on Verify: %v", err)
}
}
Loading

0 comments on commit 2465e9f

Please sign in to comment.