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

HTTP Provider Compatibility Suite #638

Merged
merged 6 commits into from
Mar 27, 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
40 changes: 40 additions & 0 deletions tests/v3/compatibility_suite/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
import shutil
import subprocess
from pathlib import Path
from typing import Any, Generator, Union

import pytest
from testcontainers.compose import DockerCompose # type: ignore[import-untyped]
from yarl import URL

from pact.v3.verifier import Verifier


@pytest.fixture(scope="session", autouse=True)
Expand All @@ -28,3 +33,38 @@ def _submodule_init() -> None:
)
raise RuntimeError(msg)
subprocess.check_call([git_exec, "submodule", "init"]) # noqa: S603


@pytest.fixture()
def verifier() -> Verifier:
"""Return a new Verifier."""
return Verifier()


@pytest.fixture(scope="session")
def broker_url(request: pytest.FixtureRequest) -> Generator[URL, Any, None]:
"""
Fixture to run the Pact broker.

This inspects whether the `--broker-url` option has been given. If it has,
it is assumed that the broker is already running and simply returns the
given URL.

Otherwise, the Pact broker is started in a container. The URL of the
containerised broker is then returned.
"""
broker_url: Union[str, None] = request.config.getoption("--broker-url")

# If we have been given a broker URL, there's nothing more to do here and we
# can return early.
if broker_url:
yield URL(broker_url)
return

with DockerCompose(
Path(__file__).parent / "util",
compose_file_name="pact-broker.yml",
pull=True,
) as _:
yield URL("http://pactbroker:pactbroker@localhost:9292")
return
54 changes: 54 additions & 0 deletions tests/v3/compatibility_suite/definition-update.diff
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,57 @@ index 94fda44..2838116 100644
| file: multipart2-body.xml |
And a Pact file for interaction 10 is to be verified
When the verification is run
diff --git a/features/V2/http_provider.feature b/features/V2/http_provider.feature
index d51df8b..57c58e7 100644
--- a/features/V2/http_provider.feature
+++ b/features/V2/http_provider.feature
@@ -10,15 +10,15 @@ Feature: Basic HTTP provider

Scenario: Supports matching rules for the response headers (positive case)
Given a provider is started that returns the response from interaction 1, with the following changes:
- | headers |
- | 'X-TEST: 1000' |
+ | response headers |
+ | 'X-TEST: 1000' |
And a Pact file for interaction 1 is to be verified
When the verification is run
Then the verification will be successful

Scenario: Supports matching rules for the response headers (negative case)
Given a provider is started that returns the response from interaction 1, with the following changes:
- | headers |
+ | response headers |
| 'X-TEST: 123ABC' |
And a Pact file for interaction 1 is to be verified
When the verification is run
@@ -27,7 +27,7 @@ Feature: Basic HTTP provider

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

Scenario: Verifies the response body (negative case)
Given a provider is started that returns the response from interaction 2, with the following changes:
- | body |
+ | response body |
| JSON: { "one": 100, "two": "b" } |
And a Pact file for interaction 2 is to be verified
When the verification is run
diff --git a/features/V4/http_provider.feature b/features/V4/http_provider.feature
index be3d1ff..8e15a13 100644
--- a/features/V4/http_provider.feature
+++ b/features/V4/http_provider.feature
@@ -9,7 +9,7 @@ Feature: HTTP provider

Scenario: Verifying a pending HTTP interaction
Given a provider is started that returns the response from interaction 1, with the following changes:
- | body |
+ | response body |
| file: basic2.json |
And a Pact file for interaction 1 is to be verified, but is marked pending
When the verification is run
Loading
Loading