Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V1 provider compatibility suite #631

Merged
merged 15 commits into from
Mar 22, 2024
Merged
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
77 changes: 73 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,30 @@ env:
HATCH_VERBOSE: 1

jobs:
test:
test-container:
name: >-
Tests py${{ matrix.python-version }} on ${{ matrix.os }}

runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}

services:
broker:
image: pactfoundation/pact-broker:latest@sha256:8f10947f230f661ef21f270a4abcf53214ba27cd68063db81de555fcd93e07dd
ports:
- "9292:9292"
env:
# Basic auth credentials for the Broker
PACT_BROKER_ALLOW_PUBLIC_READ: "true"
PACT_BROKER_BASIC_AUTH_USERNAME: pactbroker
PACT_BROKER_BASIC_AUTH_PASSWORD: pactbroker
# Database
PACT_BROKER_DATABASE_URL: sqlite:////tmp/pact_broker.sqlite

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
os: [ubuntu-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
experimental: [false]
include:
Expand All @@ -42,6 +55,12 @@ jobs:
with:
submodules: true

- name: Apply temporary definitions update
shell: bash
run: |
cd tests/v3/compatibility_suite
patch -p1 -d definition < definition-update.diff

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
with:
Expand All @@ -51,8 +70,20 @@ jobs:
- name: Install Hatch
run: pip install --upgrade hatch

- name: Ensure broker is live
run: |
i=0
until curl -sSf http://localhost:9292/diagnostic/status/heartbeat; do
i=$((i+1))
if [ $i -gt 120 ]; then
echo "Broker failed to start"
exit 1
fi
sleep 1
done

- name: Run tests
run: hatch run test
run: hatch run test --broker-url=http://pactbroker:pactbroker@localhost:9292 --container

- name: Upload coverage
# TODO: Configure code coverage monitoring
Expand All @@ -61,12 +92,50 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}

test-no-container:
name: >-
Tests py${{ matrix.python-version }} on ${{ matrix.os }}

runs-on: ${{ matrix.os }}
continue-on-error: ${{ matrix.experimental }}

strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
experimental: [false]

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
submodules: true

- name: Apply temporary definitions update
shell: bash
run: |
cd tests/v3/compatibility_suite
patch -p1 -d definition < definition-update.diff

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5
with:
python-version: ${{ matrix.python-version }}
cache: pip

- name: Install Hatch
run: pip install --upgrade hatch

- name: Run tests
run: hatch run test

test-conlusion:
name: Test matrix complete

runs-on: ubuntu-latest
needs:
- test
- test-container
- test-no-container

steps:
- run: echo "Test matrix completed successfully."
Expand Down
13 changes: 13 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,16 @@ def pytest_addoption(parser: pytest.Parser) -> None:
),
type=str,
)
parser.addoption(
"--container",
action="store_true",
help="Run tests using a container",
)


def pytest_runtest_setup(item: pytest.Item) -> None:
"""
Hook into the setup phase of tests.
"""
if "container" in item.keywords and not item.config.getoption("--container"):
pytest.skip("need --container to run this test")
8 changes: 6 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,16 @@ filterwarnings = [
]

log_level = "NOTSET"
log_format = "%(asctime)s [%(levelname)-8s] %(name)s: %(message)s"
log_date-format = "%H:%M:%S"
log_format = "%(asctime)s.%(msecs)03d [%(levelname)-8s] %(name)s: %(message)s"
log_date_format = "%H:%M:%S"

markers = [
# Marker for tests that require a container
"container",

# Markers for the compatibility suite
"consumer",
"provider",
]

################################################################################
Expand Down
12 changes: 6 additions & 6 deletions src/pact/v3/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6638,9 +6638,9 @@ def verifier_set_no_pacts_is_error(handle: VerifierHandle, *, enabled: bool) ->
def verifier_set_publish_options(
handle: VerifierHandle,
provider_version: str,
build_url: str,
provider_tags: List[str],
provider_branch: str,
build_url: str | None,
provider_tags: List[str] | None,
provider_branch: str | None,
) -> None:
"""
Set the options used when publishing verification results to the Broker.
Expand All @@ -6667,10 +6667,10 @@ def verifier_set_publish_options(
retval: int = lib.pactffi_verifier_set_publish_options(
handle._ref,
provider_version.encode("utf-8"),
build_url.encode("utf-8"),
build_url.encode("utf-8") if build_url else ffi.NULL,
[ffi.new("char[]", t.encode("utf-8")) for t in provider_tags or []],
len(provider_tags),
provider_branch.encode("utf-8"),
len(provider_tags or []),
provider_branch.encode("utf-8") if provider_branch else ffi.NULL,
)
if retval != 0:
msg = f"Failed to set publish options for {handle}."
Expand Down
10 changes: 5 additions & 5 deletions src/pact/v3/verifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ def set_error_on_empty_pact(self, *, enabled: bool = True) -> Self:
def set_publish_options(
self,
version: str,
url: str,
branch: str,
url: str | None = None,
branch: str | None = None,
tags: list[str] | None = None,
) -> Self:
"""
Expand Down Expand Up @@ -589,7 +589,7 @@ def _add_source_remote(

pact.v3.ffi.verifier_url_source(
self._handle,
str(url),
str(url.with_user(None).with_password(None)),
username,
password,
token,
Expand Down Expand Up @@ -686,14 +686,14 @@ def broker_source( # noqa: PLR0913
if selector:
return BrokerSelectorBuilder(
self,
str(url),
str(url.with_user(None).with_password(None)),
username,
password,
token,
)
pact.v3.ffi.verifier_broker_source(
self._handle,
str(url),
str(url.with_user(None).with_password(None)),
username,
password,
token,
Expand Down
79 changes: 79 additions & 0 deletions tests/v3/compatibility_suite/definition-update.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
diff --git a/features/V1/http_provider.feature b/features/V1/http_provider.feature
index 94fda44..2838116 100644
--- a/features/V1/http_provider.feature
+++ b/features/V1/http_provider.feature
@@ -118,16 +118,16 @@ Feature: Basic HTTP provider

Scenario: Verifies the response status code
Given a provider is started that returns the response from interaction 1, with the following changes:
- | status |
- | 400 |
+ | response |
+ | 400 |
And a Pact file for interaction 1 is to be verified
When the verification is run
Then the verification will NOT be successful
And the verification results will contain a "Response status did not match" error

Scenario: Verifies the response headers
- Given a provider is started that returns the response from interaction 1, with the following changes:
- | headers |
+ Given a provider is started that returns the response from interaction 5, with the following changes:
+ | response headers |
| 'X-TEST: Compatibility' |
And a Pact file for interaction 5 is to be verified
When the verification is run
@@ -142,7 +142,7 @@ Feature: Basic HTTP provider

Scenario: Response with plain text body (negative case)
Given a provider is started that returns the response from interaction 6, with the following changes:
- | body |
+ | response body |
| Hello Compatibility Suite! |
And a Pact file for interaction 6 is to be verified
When the verification is run
@@ -157,7 +157,7 @@ Feature: Basic HTTP provider

Scenario: Response with JSON body (negative case)
Given a provider is started that returns the response from interaction 1, with the following changes:
- | body |
+ | response body |
| JSON: { "one": 100, "two": "b" } |
And a Pact file for interaction 1 is to be verified
When the verification is run
@@ -172,7 +172,7 @@ Feature: Basic HTTP provider

Scenario: Response with XML body (negative case)
Given a provider is started that returns the response from interaction 7, with the following changes:
- | body |
+ | response body |
| XML: <?xml version="1.0" encoding="UTF-8" ?><values><one>A</one></values> |
And a Pact file for interaction 7 is to be verified
When the verification is run
@@ -187,7 +187,7 @@ Feature: Basic HTTP provider

Scenario: Response with binary body (negative case)
Given a provider is started that returns the response from interaction 8, with the following changes:
- | body |
+ | response body |
| file: spider.jpg |
And a Pact file for interaction 8 is to be verified
When the verification is run
@@ -202,7 +202,7 @@ Feature: Basic HTTP provider

Scenario: Response with form post body (negative case)
Given a provider is started that returns the response from interaction 9, with the following changes:
- | body |
+ | response body |
| a=1&b=2&c=33&d=4 |
And a Pact file for interaction 9 is to be verified
When the verification is run
@@ -217,7 +217,7 @@ Feature: Basic HTTP provider

Scenario: Response with multipart body (negative case)
Given a provider is started that returns the response from interaction 10, with the following changes:
- | body |
+ | response body |
| file: multipart2-body.xml |
And a Pact file for interaction 10 is to be verified
When the verification is run
Loading
Loading