Giter Site home page Giter Site logo

ngadde / example-bi-directional-provider-restassured Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pactflow/example-bi-directional-provider-restassured

0.0 0.0 0.0 696 KB

Example spring boot provider using RestAssured and the Pactflow bi-directional contracts feature

License: MIT License

Shell 14.68% Java 64.07% Makefile 21.25%

example-bi-directional-provider-restassured's Introduction

Example Java Provider - RestAssured

Build Status

Can I deploy Status

Overview of Example

This is an example of a Spring boot "Product" API Provider that uses RestAssured, Pact, Pactflow and GitHub Actions to generate and publish Pact provider contracts.

It performs pre-deployment cross-compatability checks to ensure that it is compatible with specified consumers using the Bi-Directional contract capability of Pactflow.

See the full Pactflow Bi-Directional Workshop for which this can be substituted in as the "provider".

Overview of Part of Bi-Directional Contract Testing Flow

In the following diagram, you can see how the provider testing process works.

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.

Provider Test

The project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.

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

  • Test
    • Run tests to check spec compliance with openAPI spec
    • Create branch tag via Pact CLI
    • Publish openAPI spec, along with a version with the name of the current branch
    • Check if we are safe to deploy to Production with can-i-deploy (ie. has the cross-contract validation has been successfully performed)
  • Deploy (only from <main|master>)
    • Deploy app to Production
    • Record the Production deployment in the Pact Broker

Provider Pipeline

Compatibile with Consumers

This project is currently compatible with the following consumers(s):

Pre-requisites

Software:

Environment variables

To be able to run some of the commands locally, you will need to export the following environment variables into your shell:

Usage

Steps

  • make test - run the tests locally
  • make fake_ci - run the CI process, but locally

OS/Platform specific considerations

The makefile is configured to run on Unix based systems such as you would find in most common CI/CD pipelines.

They can be run locally on Unix/Mac, or on Windows via WSL2.

Windows

You can still try this example locally on Windows using powershell and running commands manually.

Click to see windows specific instructions here

These will be the same commands that are used in the makefile with a few manual tweaks.

  1. Make sure you have set all of the environment variables, in powershell they can be set like so.

     $env:GIT_BRANCH="main"
    
  2. Publish the pact that was generated. The step uses the pact-cli docker image to publish the pact to your pactflow account. The path for <path_to_project_root> needs to be converted from Windows paths to UNIX ones as the Docker container is using UNIX. Either hard code this or set it as another environment variable.

    C:\Users\Person\Documents\example-bi-directional-consumer-dotnet

    becomes

    /c/Users/Candy/Documents/Pactflow/example-bi-directional-consumer-dotnet

    $env:VARIABLE_NAME refers to the environment variables in windows.

    docker run --rm -v <path_to_project_root>:<path_to_project_root> -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli publish <path_to_pacts_folder> --consumer-app-version $env:GIT_COMMIT --tag $env:GIT_BRANCH
    
    
  3. Check can-i-deploy to see if your provider is compatible with your pact.

    docker run --rm -v <path_to_project_root>:<path_to_project_root> -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli  broker can-i-deploy --pacticipant pactflow-example-bi-directional-consumer-dotnet --version $env:GIT_COMMIT --to-environment production  --retry-while-unknown 0 --retry-interval 10
    
  4. Have a look at what other commands are available in the Makefile. All of them can be ran locally from Powershell by changing the windows paths to UNIX and replacing the environment variable references. Any variable referenced as ${VARIABLE} can be changed to $env:VARIABLE to reference environment variables in Powershell.

Caveats

Related topics / posts / discussions

Other examples of how to do this form of testing

Found an issue?

Reach out via a GitHub Issue, or reach us over in the Pact foundation Slack

example-bi-directional-provider-restassured's People

Contributors

you54f avatar mefellows avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.