Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ jobs:
working-directory: ${{ env.WORKSPACE_ROOT }}/c/provider
run: PACT_FFI_PREBUILT_DIR="$WORKSPACE_ROOT/rust/pact_ffi/build/install" just run

# Runs the compatibility suite through the C API, against the library and header installed above.
- name: Run FFI compatibility suite
working-directory: ${{ env.WORKSPACE_ROOT }}/compatibility-suite-ffi
run: cargo test --no-fail-fast

- name: Save Conan packages
if: github.ref == 'refs/heads/master' && steps.conan-cache.outputs.cache-hit != 'true'
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ build/
pkg/

compatibility-suite/Cargo.lock
compatibility-suite-ffi/Cargo.lock
41 changes: 41 additions & 0 deletions compatibility-suite-ffi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "pact-ffi-compat"
version = "0.1.0"
edition = "2021"
publish = false
description = "Pact compatibility suite driven only through the pact_ffi C ABI, logging each step's FFI calls"

[dependencies]
anyhow = "1"
base64 = "0.22"
cucumber = "0.23"
libloading = "0.8"
regex = "1"
reqwest = { version = "0.12", default-features = false }
roxmltree = "0.20"
serde_json = "1"
tokio = { version = "1", features = ["macros", "rt-multi-thread", "net", "io-util"] }
url = "2"

[build-dependencies]
bindgen = "0.72"

[[test]]
name = "consumer"
harness = false

[[test]]
name = "provider"
harness = false

[[test]]
name = "matching"
harness = false

[[test]]
name = "generators"
harness = false

[[test]]
name = "message"
harness = false
42 changes: 42 additions & 0 deletions compatibility-suite-ffi/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# FFI compatibility suite

Runs the [Pact compatibility suite](https://github.com/pact-foundation/pact-compatibility-suite) through the
`pact_ffi` C API instead of the Rust crates. It uses the same copy of the suite as `../compatibility-suite`
(`../compatibility-suite/pact-compatibility-suite`), so the two runners check the same features.

The bindings are generated from `pact.h` at build time and the library is loaded at run time, so one build of the
runner can test any `libpact_ffi`.

## Running

Build and install pact_ffi first (this also generates the header, which needs the nightly toolchain for cbindgen):

```bash
.github/scripts/ffi-examples.sh
```

Then, from this directory:

```bash
cargo test --no-fail-fast
```

| Variable | Default |
|-------------------|---------------------------------------------------------------------------------|
| `PACT_FFI_HEADER` | `../rust/pact_ffi/build/install/include/pact.h` (read at build time) |
| `PACT_FFI_LIB` | `../rust/pact_ffi/build/install/lib/<libpact_ffi.so, .dylib or pact_ffi.dll>` |
| `FFI_TRACE_DIR` | `target/ffi-trace`: each scenario's FFI calls, one file per scenario |

## Tests

| Test | Features |
|--------------|----------------------------------------------------------------------------------|
| `consumer` | V1–V4 `http_consumer` |
| `provider` | V1–V4 `*provider` (HTTP and message providers) |
| `matching` | V3 `http_matching` and `matching_rules`, V4 `matching_rules` |
| `generators` | V3 `generators` and `http_generators`, V4 `generators` |
| `message` | V3 `message_consumer`, V4 `message_consumer`, `synchronous_message_consumer`, `v4` |

Scenarios tagged `wip` are skipped. `tests/matching.rs` also skips one known failure: the mock server reads a
0-byte body as no body, so the V4 "not empty matcher with binary data (negative case)" scenario can't get its
mismatch.
22 changes: 22 additions & 0 deletions compatibility-suite-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Generates runtime-loaded bindings for pact.h, so one binary can run against any libpact_ffi.
// The header defaults to the one `.github/scripts/ffi-examples.sh` installs; set PACT_FFI_HEADER to use another.
use std::{env, path::PathBuf};

fn main() {
let header = env::var("PACT_FFI_HEADER").unwrap_or_else(|_| {
concat!(env!("CARGO_MANIFEST_DIR"), "/../rust/pact_ffi/build/install/include/pact.h").to_string()
});
println!("cargo:rerun-if-env-changed=PACT_FFI_HEADER");
println!("cargo:rerun-if-changed={header}");
bindgen::Builder::default()
.header(&header)
.allowlist_function("pactffi_.*")
.allowlist_type("PactHandle|InteractionHandle|InteractionPart|PactSpecification|VerifierHandle|MessageContents|AsynchronousMessage|SynchronousMessage|PactAsyncMessageIterator|PactSyncMessageIterator|MessageMetadataIterator|MessageMetadataPair|Generator|GeneratorCategoryIterator|GeneratorKeyValuePair|GeneratorCategory")
.prepend_enum_name(false)
.dynamic_library_name("PactFfi")
.dynamic_link_require_all(false)
.generate()
.expect("bindgen failed on pact.h")
.write_to_file(PathBuf::from(env::var("OUT_DIR").unwrap()).join("bindings.rs"))
.unwrap();
}
Loading
Loading