Kube Cloud Pt6 | Fulfill the Consumer Contract Test for REST Endpoint

Kube Cloud Pt6 | Fulfill the Consumer Contract Test for REST Endpoint

Kube Cloud Pt6 | Contract Testing

full course
  1. Kube Cloud Pt6 | Contract Testing
  2. Kube Cloud Pt6 | Consumer Contract Tests for REST Endpoints
  3. Kube Cloud Pt6 | Provider Contract Test for REST Endpoints
  4. Kube Cloud Pt6 | Fulfill the Consumer Contract Test for REST Endpoint
  5. Kube Cloud Pt6 | Break the Contract from a Consumer Change
  6. Kube Cloud Pt6 | Synchronous Contract Testing Conclusion

Now we need to fulfill our contract with the consumer. We just need to add a few pieces that that a consumer build will trigger a provider verification.

Add a Verification Workflow

Go back to your branch in message-generator and add a new github action workflow called verify-changed-pact.yaml with this content

name: Verify changed pact

on:
  repository_dispatch:
    types:
      - pact_changed

env:
  PACTFLOW_URL: https://bullyrooks.pactflow.io
  PACTFLOW_TOKEN: ${{secrets.PACTFLOW_TOKEN}}
  PACTBROKER_HOST: bullyrooks.pactflow.io
  GIT_COMMIT: ${{ github.sha }}
  GITHUB_REF: ${{ github.ref }}
  PACT_URL: ${{ github.event.client_payload.pact_url }}

jobs:
  verify-changed-pact:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
        with:
          fetch-depth: 0  # Shallow clones should be disabled for a better relevancy of analysis

      - uses: actions-ecosystem/[email protected]
        id: get-latest-tag

      - name: Echo release version
        run: |
          echo "RELEASE_VERSION=${{ steps.get-latest-tag.outputs.tag }}" >> $GITHUB_ENV
          echo ${{ env.RELEASE_VERSION }}
      - name: Set up JDK 11
        uses: actions/[email protected]
        with:
          java-version: '11'
          distribution: 'adopt'
          cache: maven
      - name: Verify Contract Tests
        run: |
          ./mvnw -B verify -Pcontract -X \
          -Dpactbroker.host=${{env.PACTBROKER_HOST}} \
          -Dpact.verifier.publishResults=true \
          -Dpact.provider.version=${{ env.RELEASE_VERSION }} \
          -Dpact.provider.branch=main \
          -Dpact.provider.tag=okteto \
          -DPACT_CONSUMER_SELECTOR_TAG=okteto,pre-okteto,development

This is a unique workflow that will only verify and publish the results of the provider tests you can see that it’s being triggered by a repository dispatch action. We’re going to setup a webhook callback in pactflow to trigger this.

This is not a breaking change, so go ahead and build to the feature branch and merge to main. We’ll need this on main in order to let the consumer build trigger it.

Create the Verification Webhook

I’m following the pactflow documentation here where they explain how to setup a personal access token and add it to the secrets in pactflow in order to create the webhook. I’ll skip most of that.

This is what my webhook looks like:

Kick Off the Build

Go back into github, find your pull request and go to the build failure. You should see a button that will let you rebuild. Click that button

You should see your build succeed:

And your pull request should look ready for merge

Additionally, if you look at the builds in message-generator you should see that your verification workflow passed:

And if you look at your pact in pactflow you should see that the feature branch of consumer contract was fulfilled by the version in okteto

So go ahead and merge to main. Again, we should see cloud-application succeed

We should see the verification pass

And we should see that our contract is fulfilled and that the environments for all of the services are in okteto

0 comments on “Kube Cloud Pt6 | Fulfill the Consumer Contract Test for REST EndpointAdd yours →

Leave a Reply

Your email address will not be published.