Protobuf¶
Protocol Buffers Plugin Example for Pact Python v3.
This module provides an example of how to use Pact plugins to handle different content types in contract testing. Specifically, this example demonstrates the use of the protobuf plugin to test interactions involving Protocol Buffers (protobuf) message serialization.
For detailed information about Protocol Buffers, the generated files, and the
domain model used in this example, see the proto
module documentation.
Pact and the Plugin Ecosystem¶
Pact is traditionally focused on HTTP-based interactions with text-based (primarily JSON) payloads. However, modern microservices architectures often use various content types and transport mechanisms beyond simple text over HTTP. To address this, Pact allows for extensibility through a plugin system that supports different content types and protocols.
Pact plugins extend the core functionality of Pact to support different content types, transport protocols, and matching strategies. The plugin system allows Pact to:
- Handle different content types (e.g., protobuf)
- Support various transport mechanisms (e.g., gRPC)
- Provide specialized matching rules for different data formats
- Enable extensibility without modifying the core Pact library
This Example¶
This example demonstrates how to use the Pact protobuf plugin to test interactions involving protobuf messages sent over HTTP. It is assumed that you have a basic understanding of Pact and Protocol Buffers.
Classes¶
Functions¶
address_book() -> AddressBook
¶
Create a sample address book.
This function constructs an AddressBook
instance containing three
Person
instances:
- Alice with ID 1
- Bob with ID 2
- Charlie with ID 3