/pact-matt-plugin

Pact plugin for the MATT protocol (example project)

Primary LanguageCMIT LicenseMIT

Pact Plugin Example - The MATT protocol

This is an example plugin for the Pact framework.

It implements a custom Protocol and Content Matcher for a fictional protocol - the MATT protocol.

Install

pact-plugin-cli -y install https://github.com/mefellows/pact-matt-plugin/releases/tag/v0.0.1

Writing tests

Synchronous Messages

Set the request/response all in one go:

mattMessage := `{"request": {"body": "hellotcp"}, "response":{"body":"tcpworld"}}`

HTTP

Separate out the body on the request/response part of the interaction:

	mattRequest := `{"request": {"body": "hello"}}`
	mattResponse := `{"response":{"body":"world"}}`

Use Case

The MATT protocol is a simple text-based protocol, designed for efficient communication of messages to a Matt.

MATT messages are composed of basic text values, where the start and end of the communication must contain the word "MATT".

i.e. MATT<message>MATT

in BNF it would be something like this:

<message>   ::= <delimeter> <word> <delimeter>
<delimeter> ::= "MATT"
<word>      ::= <character> | <word> <character>
<character> ::= <letter> | <number> | <symbol>
<letter>    ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
<number>    ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
<symbol>    ::=  "|" | " " | "!" | "#" | "$" | "%" | "&" | "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | ">" | "=" | "<" | "?" | "@" | "[" | "\" | "]" | "^" | "_" | "`" | "{" | "}" | "~"

When sent over TCP, messages are terminated with the newline delimeter \n.

Developing the plugin

Build and install the plugin

The following command will build the plugin, and install into the correct plugin directory for local development:

make install_local

Regenerating the plugin protobuf definitions

If a new protobuf definition is required, copy into the io_pact_plugin folder and run the following Make task:

make proto

Prerequsites

The protoc compiler must be installed for this plugin