Skip to content

Commit

Permalink
chore: remove nock example now it is moved to a diff repo (#45)
Browse files Browse the repository at this point in the history
* chore: remove nock example now it is moved to a diff repo

* chore: remove nock from package json
  • Loading branch information
YOU54F authored Apr 6, 2022
1 parent 41a15c3 commit 203e2d4
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 405 deletions.
44 changes: 9 additions & 35 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,70 +18,44 @@ jobs:
matrix:
pact_provider:
[
# "pactflow-example-provider-dredd",
# "pactflow-example-provider-restassured",
# "pactflow-example-provider-postman",
# "pactflow-example-bi-directional-provider-dredd",
# "pactflow-example-bi-directional-provider-restassured",
# "pactflow-example-bi-directional-provider-postman",
"pactflow-example-provider",
]
pact_consumer:
[
"pactflow-example-consumer",
# "pactflow-example-consumer-nock"
]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: "12"
- name: Install for ${{ matrix.pact_consumer }} & ${{ matrix.pact_provider }}
- name: Install for ${{ matrix.pact_provider }}
run: npm i
- name: Test for ${{ matrix.pact_consumer }} & ${{ matrix.pact_provider }}
- name: Test for ${{ matrix.pact_provider }}
env:
PACTICIPANT: ${{ matrix.pact_consumer }}
PACT_PROVIDER: ${{ matrix.pact_provider }}
run: |
[[ $PACTICIPANT = pactflow-example-consumer-nock ]] && make test_nock || make test
- name: Publish pacts for ${{ matrix.pact_consumer }} & ${{ matrix.pact_provider }}
run: make test
- name: Publish pacts for${{ matrix.pact_provider }}
run: GIT_BRANCH=${GIT_REF:11} make publish_pacts
env:
PACTICIPANT: ${{ matrix.pact_consumer }}
PACT_PROVIDER: ${{ matrix.pact_provider }}

# Runs on branches as well, so we know the status of our PRs
can-i-deploy:
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
pact_consumer:
[
"pactflow-example-consumer",
# "pactflow-example-consumer-nock"
]
steps:
- uses: actions/checkout@v2
- run: docker pull pactfoundation/pact-cli:latest
- name: Can I deploy? for ${{ matrix.pact_consumer }}
env:
PACTICIPANT: ${{ matrix.pact_consumer }}
- name: Can I deploy?
run: GIT_BRANCH=${GIT_REF:11} make can_i_deploy

# Only deploy from master
deploy:
runs-on: ubuntu-latest
needs: can-i-deploy
strategy:
matrix:
pact_consumer:
[
"pactflow-example-consumer",
# "pactflow-example-consumer-nock"
]
steps:
- uses: actions/checkout@v2
- run: docker pull pactfoundation/pact-cli:latest
- name: Deploy for ${{ matrix.pact_consumer }}
- name: Deploy
run: GIT_BRANCH=${GIT_REF:11} make deploy
if: github.ref == 'refs/heads/master'
env:
PACTICIPANT: ${{ matrix.pact_consumer }}
15 changes: 1 addition & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Default to the read only token - the read/write token will be present on Travis CI.
# It's set as a secure environment variable in the .travis.yml file
GITHUB_ORG="pactflow"
PACTICIPANT ?= ${PACTICIPANT} || "pactflow-example-consumer"
PACTICIPANT="pactflow-example-consumer"
GITHUB_WEBHOOK_UUID := "04510dc1-7f0a-4ed2-997d-114bfa86f8ad"
PACT_CHANGED_WEBHOOK_UUID := "8e49caaa-0498-4cc1-9368-325de0812c8a"
PACT_CLI="docker run --rm -v ${PWD}:${PWD} -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli"
Expand All @@ -24,7 +24,6 @@ all: test
## ====================

ci: test publish_pacts can_i_deploy $(DEPLOY_TARGET)
ci_nock: test_nock publish_pacts can_i_deploy $(DEPLOY_TARGET)

# Run the ci target from a developer machine with the environment variables
# set as if it was on CI.
Expand All @@ -36,14 +35,6 @@ fake_ci: .env
REACT_APP_API_BASE_URL=http://localhost:8080 \
make ci

fake_ci_nock: .env
@CI=true \
GIT_COMMIT=`git rev-parse --short HEAD`+`date +%s` \
GIT_BRANCH=`git rev-parse --abbrev-ref HEAD` \
REACT_APP_API_BASE_URL=http://localhost:8080 \
PACTICIPANT=pactflow-example-consumer-nock \
make ci_nock

publish_pacts: .env
@echo "\n========== STAGE: publish pacts ==========\n"
@"${PACT_CLI}" publish ${PWD}/pacts --consumer-app-version ${GIT_COMMIT} --tag ${GIT_BRANCH}
Expand All @@ -56,10 +47,6 @@ test: .env
@echo "\n========== STAGE: test (pact) ==========\n"
npm run test:pact

test_nock: .env
@echo "\n========== STAGE: test (nock) ==========\n"
PACTICIPANT=pactflow-example-consumer-nock npm run test:nock

## =====================
## Deploy tasks
## =====================
Expand Down
65 changes: 0 additions & 65 deletions README-bi-directional.md

This file was deleted.

48 changes: 2 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,6 @@ The project uses a Makefile to simulate a very simple build pipeline with two st

See the [Pactflow CI/CD Workshop](https://github.com/pactflow/ci-cd-workshop).

## Bi-directional Contracts Feature (BYO Tools)

![Build](https://github.com/pactflow/example-consumer/workflows/Build/badge.svg)

[![Can I deploy Status](https://testdemo.pactflow.io/pacticipants/pactflow-example-consumer-msw/branches/master/latest-version/can-i-deploy/to-environment/production/badge)](https://testdemo.pactflow.io/pacticipants/pactflow-example-consumer-nock/branches/master/latest-version/can-i-deploy/to-environment/production/badge)

_NOTE: if you're running the CI/CD workshop, you can ignore this section. This is an extension to the example that demonstrates a new [feature](https://github.com/pactflow/roadmap/issues/4) in developer preview._

This is an example of a Node consumer using Pact to create a consumer driven contract, and sharing it via [Pactflow](https://pactflow.io).

It implements a "Product" website, to demonstrate the new bi-directional contract capability of Pactflow (previously referred to as Provider driven contracts, or collaborative contracts). See the [Provider](https://github.com/pactflow/example-pactflow-example-provider-dredd) counterpart.

It is using a private tenant on Pactflow. The latest version of the Example Pactflow Consumer/Example Pactflow Provider (Dredd) pact is published [here](https://testdemo.pactflow.io/overview/provider/pactflow-example-provider-dredd/consumer/pactflow-example-consumer).

In the following diagram, you can see how the consumer testing process works - it's the same as the current Pact process! (We do show an alternative using Nock's record/replay functionality)

When we call "can-i-deploy" the cross-contract validation process kicks off on Pactflow, to ensure any consumer consumes a valid subset of the OAS for the provider.

![Consumer Test](docs/consumer-scope.png "Consumer Test")

When you run the CI pipeline (see below for doing this), the pipeline should perform the following activities (simplified):

![Consumer Pipeline](docs/consumer-pipeline.png "Consumer Pipeline")

### Pre-requisites

**Software**:
Expand All @@ -62,30 +38,10 @@ To be able to run some of the commands locally, you will need to export the foll

* `PACT_BROKER_TOKEN`: a valid [API token](https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token) for Pactflow
* `PACT_BROKER_BASE_URL`: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.io
* `PACT_PROVIDER=pactflow-example-provider-dredd`: this changes the default provider to the Dredd based provider (https://github.com/pactflow/example-provider-dredd)
* `PACT_PROVIDER=pactflow-example-provider-postman`: ... Postman (https://github.com/pactflow/example-provider-postman)
* `PACT_PROVIDER=pactflow-example-provider-restassured`: ... Rest Assured (https://github.com/pactflow/example-provider-restassured)

### Usage

#### Pact use case

* `make test` - run the pact test locally
* `make fake_ci` - run the CI process locally

#### BYO Tool use case with Nock (record/replay example)

NOTE: The nock recordings are already in the project, in the `./fixtures` directory, see below for how to obtain these recordings.

* `make clean` - ensure previous pacts are cleared
* `make test_nock` - run the nock test locally
* `make fake_ci_nock` - run the nock version of the CI process locally

*Re-record nock fixtures*

You first need to start up the provider API in order to obtain nock recordings. The API must be running on `http://localhost:3001` for this step to work.

For the default [Provider](https://github.com/pactflow/example-provider-dredd) designed for this workshop, you can simply start it up by running `npm start` in the root directory of the provider project, as per its README.


* `npm run test:record` - this will run nock in record mode, and your api client will issue real requests to the API
* `npm run test:nock` - run the nock tests in replay only mode, validating all stubs were used in the process, and writing a pact file if successful
* `make fake_ci` - run the CI process locally
80 changes: 0 additions & 80 deletions fixtures/nock.json

This file was deleted.

Loading

0 comments on commit 203e2d4

Please sign in to comment.