Skip to content

About

Pact plugin for contract testing Apache Avro messages, written in Rust

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

18 stars

Watchers

1 watching

Forks

Repository files navigation

Pact Avro Plugin Coverage

Pact Avro Plugin logo

Pact plugin for testing messages serialised by Apache Avro using the Pact contract testing framework.

Installation

Install the latest release into your Pact plugin directory:

curl -fsSL https://github.com/hominux/pact-avro-plugin/releases/latest/download/install-plugin.sh | sh

Binaries exist for Linux, macOS and Windows on x86_64 and aarch64. See the getting started guide for the Pact CLI install and platform requirements. On Windows, run the command from Git Bash, MSYS or Cygwin.

Usage

A consumer test loads the plugin, points it at an Avro schema, and describes the fields it relies on. The plugin encodes a real Avro message from that description and records matching rules in the pact.

item.avsc
{
  "type": "record",
  "name": "Item",
  "namespace": "com.example",
  "fields": [
    { "name": "id", "type": "long" },
    { "name": "name", "type": "string" }
  ]
}
Consumer test (Rust, with pact_consumer)
let mut builder = PactBuilder::new_v4("order-consumer", "order-provider")
    .using_plugin("avro", None)
    .await;

builder
    .message_interaction("an item is created", |mut i| async move {
        i.contents_from(json!({
            "pact:content-type": "avro/binary",
            "pact:avro": "schemas/item.avsc",
            "pact:record-name": "Item",
            "id": "notEmpty('100')",
            "name": "notEmpty('widget')"
        }))
        .await;
        i
    })
    .await;

The pact file then holds the encoded message and one matching rule per field (trimmed):

{
  "contents": {
    "content": "yAEMd2lkZ2V0",
    "contentType": "avro/binary;record=Item",
    "encoded": "base64"
  },
  "description": "an item is created",
  "matchingRules": {
    "body": {
      "$.id": { "combine": "AND", "matchers": [{ "match": "notEmpty" }] },
      "$.name": { "combine": "AND", "matchers": [{ "match": "notEmpty" }] }
    }
  },
  "type": "Asynchronous/Messages"
}

The plugin works with any Pact language that supports plugins. See the testing guide for the provider side and a larger schema, and the configuration reference for every key and error.

Development Roadmap

This plugin is released under the MIT License and is copyright © 2021-23 Ali Ustek.


💝 Support This Project

If this repository saves you time and effort, please consider supporting it!

About

Pact plugin for contract testing Apache Avro messages, written in Rust

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

18 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages