Giter Site home page Giter Site logo

cdc-pact-gophercon-2021's Introduction

CDC Pact

  • Pact is a consumer-driven contract testing framework. Born out of a microservices boom, Pact was created to solve the problem of integration testing large, distributed systems. (Old definition)
  • How Pact works slide from pactflow.io
  • ✅ Rescue for integration test cost.
  • ✅ Gives fast feedback
  • ✅ Implement any programming language you want. For example
  • ✅ No dedicated test environments (it works on dev machine)

Project Architecture 🚀

ℹ️ Terminology

Interaction: A request and response pair. A pact consists of a collection of interactions.

Pact file: A file containing the JSON serialised interactions (requests and responses) that were defined in the consumer tests. This is the Contract.

Pact verification: To verify a Pact contract, the requests contained in a Pact file are replayed against the provider code, and the responses returned are checked to ensure they match those expected in the Pact file.

Pact Specification A provider state name is specified when writing the consumer specs, then, when the pact verification is set up in the provider the same name will be used to identify the set up code block that should be run before the request is executed.

ℹ️ Pact Broker

The Pact Broker is an open source tool that requires you to deploy, administer and host yourself. It enables you to share your pacts and verification results between projects

Pact Generation and Verification Flow 🚀

Matching on types

dsl.Like(content) tells Pact that value is not important, just focus type match.

Matching on arrays

dsl.EachLike(content, min) tells Pact that the value should be array type, consisting of elements like those passed in. min must be >= 1.

"fabrics": dsl.EachLike(dsl.MapMatcher{
    "title":    dsl.Like("Pamuk"),
    "count":    dsl.Integer()
}, 1),

Matching by regular expression

dsl.Term(example, matcher) tells Pact that the value should match using a given regular expression, using example in mock responses.

"type": Term("admin", "admin|user|guest") => "type": "admin"

Match common formats

method description
Identifier() Match an ID (e.g. 42)
Integer() Match all numbers that are integers (both ints and longs)
Decimal() Match all real numbers (floating point and decimal)
HexValue() Match all hexadecimal encoded strings
Date() Match string containing basic ISO8601 dates (e.g. 2016-01-01)
Timestamp() Match a string containing an RFC3339 formatted timestapm (e.g. Mon, 31 Oct 2016 15:21:41 -0400)
Time() Match string containing times in ISO date format (e.g. T22:44:30.652Z)
IPv4Address() Match string containing IP4 formatted address
IPv6Address() Match string containing IP6 formatted address
UUID() Match strings containing UUIDs

🤘 References 💪

Pact Docs
Pact Go
Turkish Microservice Architecture Book
Pact Broker Docker
Building Microservices
Contract testing and how Pact works
Test Double
Difference between gobuild and build directive

cdc-pact-gophercon-2021's People

Watchers

James Cloos 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.