Skip to content

Commit

Permalink
fix(v3): defer setting pact broker source
Browse files Browse the repository at this point in the history
When setting that Pact broker source, the verifier name _must_ be set;
however, the FFI call to set this is deferred until the `verify()` call.
The setting of the Pact broker source (which itself depends on knowing
the verifier name) must therefore be also deferred.

Signed-off-by: JP-Ellis <[email protected]>
  • Loading branch information
JP-Ellis committed Jan 22, 2025
1 parent 954c108 commit 473388e
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions src/pact/v3/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
from contextlib import nullcontext
from datetime import date
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal, TypedDict, overload
from typing import TYPE_CHECKING, Any, Callable, Literal, TypedDict, overload

from typing_extensions import Self
from yarl import URL
Expand Down Expand Up @@ -183,6 +183,11 @@ def __init__(self, name: str, host: str | None = None) -> None:
self._state_handler: StateCallback | nullcontext[None] = nullcontext()
self._disable_ssl_verification = False
self._request_timeout = 5000
# Using a broker source requires knowing the provider name, which is
# only provided to the FFI just before verification. As such, we store
# the broker source as a hook to be called just before verification, and
# after the provider name is set.
self._broker_source_hook: Callable[[], None] | None = None

def __str__(self) -> str:
"""
Expand Down Expand Up @@ -1193,13 +1198,15 @@ def broker_source(
password,
token,
)
pact.v3.ffi.verifier_broker_source(

self._broker_source_hook = lambda: pact.v3.ffi.verifier_broker_source(
self._handle,
str(url.with_user(None).with_password(None)),
username,
password,
token,
)

return self

def verify(self) -> Self:
Expand Down Expand Up @@ -1233,6 +1240,9 @@ def verify(self) -> Self:
transport["scheme"],
)

if self._broker_source_hook:
self._broker_source_hook()

with self._message_producer, self._state_handler:
pact.v3.ffi.verifier_execute(self._handle)
logger.debug("Verifier executed")
Expand Down Expand Up @@ -1381,18 +1391,20 @@ def build(self) -> Verifier:
Returns:
The Verifier instance with the broker source added.
"""
pact.v3.ffi.verifier_broker_source_with_selectors(
self._verifier._handle, # noqa: SLF001
self._url,
self._username,
self._password,
self._token,
self._include_pending,
self._include_wip_since,
self._provider_tags or [],
self._provider_branch,
self._consumer_versions or [],
self._consumer_tags or [],
self._verifier._broker_source_hook = ( # noqa: SLF001
lambda: pact.v3.ffi.verifier_broker_source_with_selectors(
self._verifier._handle, # noqa: SLF001
self._url,
self._username,
self._password,
self._token,
self._include_pending,
self._include_wip_since,
self._provider_tags or [],
self._provider_branch,
self._consumer_versions or [],
self._consumer_tags or [],
)
)
self._built = True
return self._verifier
Expand Down

0 comments on commit 473388e

Please sign in to comment.