Packages

Erlang wrapper for Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems.

Current section

9 Versions

Jump to

Compare versions

6 files changed
+109 additions
-22 deletions
  @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6 6
7 7 ## [Unreleased]
8 8
9 + ## [0.3.2] - 2026-06-24
10 +
11 + ### Fixed
12 +
13 + - Backward compatibility fix for a breaking change introduced in [0.3.1].
14 + - Compilation issues with older ubuntu versions.
15 +
16 + ### Added
17 +
18 + - Support for verifying message pacts from service's own http endpoint.
19 + - Alpine/musl Linux support: detect musl at build time and select the correct precompiled `libpact_ffi` library ([#61](https://github.com/greyorange-labs/pact_erlang/pull/61)).
9 20
10 21 ## [0.3.1] - 2025-07-05
  @@ -12,26 +12,23 @@ PACT_FFI_VERSION := 0.4.27
12 12 PACT_FFI_BASE_URL := https://github.com/pact-foundation/pact-reference/releases/download/libpact_ffi-v$(PACT_FFI_VERSION)
13 13 PACT_H_URL := $(PACT_FFI_BASE_URL)/pact.h
14 14
15 + ifeq ($(ARCHITECTURE), x86_64)
16 + PACT_ARCH := x86_64
17 + else
18 + PACT_ARCH := aarch64
19 + endif
20 +
15 21 ifeq ($(UNAME),Linux)
16 22 CFLAGS := -O2 -Wmissing-prototypes -Wall -shared -o
17 - ifeq ($(ARCHITECTURE), arm64)
18 - PACT_FILE_NAME := libpact_ffi-linux-aarch64.a
19 - endif
20 - ifeq ($(ARCHITECTURE), aarch64)
21 - PACT_FILE_NAME := libpact_ffi-linux-aarch64.a
22 - endif
23 - ifeq ($(ARCHITECTURE), x86_64)
24 - PACT_FILE_NAME := libpact_ffi-linux-x86_64.a
23 + LIBC := $(shell $(CC) -dumpmachine 2>/dev/null | grep -q musl && echo musl || echo glibc)
24 + ifeq ($(LIBC), musl)
25 + LIBC_SUFFIX := -musl
25 26 endif
27 + PACT_FILE_NAME := libpact_ffi-linux-$(PACT_ARCH)$(LIBC_SUFFIX).a
26 28 endif
27 29 ifeq ($(UNAME),Darwin)
28 30 CFLAGS := -undefined dynamic_lookup -shared -o
29 - ifeq ($(ARCHITECTURE), arm64)
30 - PACT_FILE_NAME := libpact_ffi-macos-aarch64.a
31 - endif
32 - ifeq ($(ARCHITECTURE), x86_64)
33 - PACT_FILE_NAME := libpact_ffi-macos-x86_64.a
34 - endif
31 + PACT_FILE_NAME := libpact_ffi-macos-$(PACT_ARCH).a
35 32 endif
36 33 PACT_FFI_URL := $(PACT_FFI_BASE_URL)/$(PACT_FILE_NAME).gz
37 34
  @@ -59,11 +56,11 @@ compile_commands.json: Makefile
59 56 @echo "}]" >> compile_commands.json
60 57
61 58 $(TARGET): $(SRC) $(LIBRARY_PATH)
62 - @$(CC) $(CFLAGS) $(TARGET) $(SRC) -I$(ERTS_INCLUDE_DIR) -I$(PACT_INCLUDE_PATH) $(LIBRARY_PATH)
59 + @$(CC) $(CFLAGS) $(TARGET) $(SRC) -I$(ERTS_INCLUDE_DIR) -I$(PACT_INCLUDE_PATH) $(LIBRARY_PATH) -lpthread -ldl
63 60
64 61 ifeq ($(UNAME),Linux)
65 62 $(PVER_EXEC_BIN): $(PVER_EXEC_SRC) $(LIBRARY_PATH)
66 - @$(CC) -o $(PVER_EXEC_BIN) ../c_src/$(PVER_EXEC_SRC) -I../c_src/include $(LIBRARY_PATH) -lm
63 + @$(CC) -o $(PVER_EXEC_BIN) ../c_src/$(PVER_EXEC_SRC) -I../c_src/include $(LIBRARY_PATH) -lm -lpthread -ldl
67 64 endif
68 65
69 66 $(LIBRARY_PATH): $(PACT_VERSION_FILE)
  @@ -22,4 +22,4 @@
22 22 [{<<"app">>,<<"thoas">>},
23 23 {<<"optional">>,false},
24 24 {<<"requirement">>,<<"~>1.2.1">>}]}]}.
25 - {<<"version">>,<<"0.3.1">>}.
25 + {<<"version">>,<<"0.3.2">>}.
  @@ -1,6 +1,6 @@
1 1 {application,pact_erlang,
2 2 [{description,"Erlang wrapper for Pact. Pact is a contract testing framework for HTTP APIs and non-HTTP asynchronous messaging systems."},
3 - {vsn,"0.3.1"},
3 + {vsn,"0.3.2"},
4 4 {modules,[]},
5 5 {registered,[]},
6 6 {applications,[kernel,stdlib,thoas,inets]},
  @@ -85,14 +85,21 @@ make_json_response(Code, Body) ->
85 85 -spec start_verifier(provider(), provider_opts()) -> gen_server:start_ret().
86 86 start_verifier(Provider, ProviderOpts) ->
87 87 Protocol = maps:get(protocol, ProviderOpts, <<"http">>),
88 + ProviderPort = maps:get(port, ProviderOpts, undefined),
88 89 {Port, HttpPid} =
89 90 case Protocol of
90 91 <<"http">> ->
91 - Port1 = maps:get(port, ProviderOpts),
92 + Port1 = ProviderPort,
92 93 {Port1, undefined};
93 94 <<"message">> ->
94 - {ok, Port1, HttpPid1} = pact_verifier:start(0, Provider),
95 - {Port1, HttpPid1}
95 + case ProviderPort of
96 + undefined ->
97 + %% Start a new port for message protocol
98 + {ok, Port1, HttpPid1} = pact_verifier:start(0, Provider),
99 + {Port1, HttpPid1};
100 + Port1 ->
101 + {Port1, undefined}
102 + end
96 103 end,
97 104 gen_server:start(
98 105 {global, {?MODULE, Provider}},
  @@ -227,7 +234,15 @@ verify_pacts_internal(VerifierRef, ProviderOpts, ProviderPortDetails) ->
227 234
228 235 case Protocol of
229 236 <<"message">> ->
230 - pact_verifier:stop(HttpPid),
237 + case HttpPid of
238 + undefined ->
239 + %% If HttpPid is undefined, it means we are not using HTTP protocol
240 + %% and we should not stop the HTTP server.
241 + ok;
242 + _ ->
243 + %% Stop the HTTP server if it was started for message protocol
244 + pact_verifier:stop(HttpPid)
245 + end,
231 246 stop_verifier(VerifierRef);
232 247 _ ->
233 248 stop_verifier(VerifierRef)
Loading more files…