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

chore: update examples to work with podman on macos #368

Closed
wants to merge 3 commits into from
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pact-broker publish /path/to/pacts/consumer-provider.json --consumer-app-version
### Python API

```python
broker = Broker(broker_base_url="http://localhost")
broker = Broker(broker_base_url="http://localhost:9292")
broker.publish("TestConsumer",
"2.0.1",
branch='consumer-branch',
Expand Down
13 changes: 8 additions & 5 deletions examples/broker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ services:
# As well as changing the image, the destination port will need to be changed
# from 9292 below, and in the nginx.conf proxy_pass section
image: pactfoundation/pact-broker:latest-multi
# PODMAN:- Error response from daemon: rootlessport cannot expose privileged port 80, you can add 'net.ipv4.ip_unprivileged_port_start=80' to /etc/sysctl.conf (currently 1024), or choose a larger port number (>= 1024): listen tcp 0.0.0.0:80: bind: permission denied
ports:
- "80:9292"
- "9292:9292"
depends_on:
- postgres
links:
- postgres
# PODMAN:- Error response from daemon: bad parameter: link is not supported
# links:
# - postgres
environment:
PACT_BROKER_DATABASE_USERNAME: postgres
PACT_BROKER_DATABASE_PASSWORD: password
Expand All @@ -47,8 +49,9 @@ services:
# terminate with SSL
nginx:
image: nginx:alpine
links:
- broker_app:broker
# PODMAN:- Error response from daemon: bad parameter: link is not supported
# links:
# - broker_app:broker
volumes:
- ./ssl/nginx.conf:/etc/nginx/conf.d/default.conf:ro
- ./ssl:/etc/nginx/ssl
Expand Down
9 changes: 5 additions & 4 deletions examples/common/sharedfixtures.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import platform
# import platform
import pathlib

import docker
Expand Down Expand Up @@ -66,10 +66,11 @@ def publish_existing_pact(broker):
"PACT_BROKER_PASSWORD": "pactbroker",
}

target_platform = platform.platform().lower()
# target_platform = platform.platform().lower()

if 'macos' in target_platform or 'windows' in target_platform:
envs["PACT_BROKER_BASE_URL"] = "http://host.docker.internal:80"
# PODMAN:- Can't bind to port <1024
# if 'macos' in target_platform or 'windows' in target_platform:
# envs["PACT_BROKER_BASE_URL"] = "http://host.docker.internal:80"

client = docker.from_env()

Expand Down
3 changes: 2 additions & 1 deletion examples/consumer/run_pytest.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -o pipefail

pytest tests --run-broker True --publish-pact 1
# PODMAN:- Log verbosely when failing tests to work out whats going on!
pytest tests --run-broker True --publish-pact 1 -rP
3 changes: 2 additions & 1 deletion examples/consumer/tests/consumer/test_user_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
# If publishing the Pact(s), they will be submitted to the Pact Broker here.
# For the purposes of this example, the broker is started up as a fixture defined
# in conftest.py. For normal usage this would be self-hosted or using PactFlow.
PACT_BROKER_URL = "http://localhost"
# PODMAN:- Can't bind to port <1024
PACT_BROKER_URL = "http://localhost:9292"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"

Expand Down
2 changes: 1 addition & 1 deletion examples/fastapi_provider/tests/provider/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# For the purposes of this example, the broker is started up as a fixture defined
# in conftest.py. For normal usage this would be self-hosted or using PactFlow.
PACT_BROKER_URL = "http://localhost"
PACT_BROKER_URL = "http://localhost:9292"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"

Expand Down
2 changes: 1 addition & 1 deletion examples/flask_provider/tests/provider/test_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# For the purposes of this example, the broker is started up as a fixture defined
# in conftest.py. For normal usage this would be self-hosted or using PactFlow.
PACT_BROKER_URL = "http://localhost"
PACT_BROKER_URL = "http://localhost:9292"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"

Expand Down
2 changes: 1 addition & 1 deletion examples/message/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ import pytest
from pact import MessageProvider


PACT_BROKER_URL = "http://localhost"
PACT_BROKER_URL = "http://localhost:9292"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"
PACT_DIR = "pacts"
Expand Down
2 changes: 1 addition & 1 deletion examples/message/tests/consumer/test_message_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

PACT_BROKER_URL = "http://localhost"
PACT_BROKER_URL = "http://localhost:9292"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"
PACT_DIR = "pacts"
Expand Down
2 changes: 1 addition & 1 deletion examples/message/tests/provider/test_message_provider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from pact import MessageProvider

PACT_BROKER_URL = "http://localhost"
PACT_BROKER_URL = "http://localhost:9292"
PACT_BROKER_USERNAME = "pactbroker"
PACT_BROKER_PASSWORD = "pactbroker"
PACT_DIR = "pacts"
Expand Down
32 changes: 16 additions & 16 deletions tests/test_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_publish_without_broker_url(self):

def test_publish_fails(self):
self.mock_Popen.return_value.returncode = 1
broker = Broker(broker_base_url="http://localhost",
broker = Broker(broker_base_url="http://localhost:9292",
broker_username="username",
broker_password="password",
broker_token="token")
Expand All @@ -44,7 +44,7 @@ def test_publish_fails(self):
self.mock_Popen.assert_called_once_with([
BROKER_CLIENT_PATH, 'publish',
'--consumer-app-version=2.0.1',
'--broker-base-url=http://localhost',
'--broker-base-url=http://localhost:9292',
'--broker-username=username',
'--broker-password=password',
'--broker-token=token',
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_publish_with_broker_url_environment_variable(self):
del os.environ["PACT_BROKER_BASE_URL"]

def test_basic_authenticated_publish(self):
broker = Broker(broker_base_url="http://localhost",
broker = Broker(broker_base_url="http://localhost:9292",
broker_username="username",
broker_password="password")

Expand All @@ -83,13 +83,13 @@ def test_basic_authenticated_publish(self):
self.mock_Popen.assert_called_once_with([
BROKER_CLIENT_PATH, 'publish',
'--consumer-app-version=2.0.1',
'--broker-base-url=http://localhost',
'--broker-base-url=http://localhost:9292',
'--broker-username=username',
'--broker-password=password',
'./TestConsumer-TestProvider.json'])

def test_token_authenticated_publish(self):
broker = Broker(broker_base_url="http://localhost",
broker = Broker(broker_base_url="http://localhost:9292",
broker_username="username",
broker_password="password",
broker_token="token")
Expand All @@ -101,14 +101,14 @@ def test_token_authenticated_publish(self):
self.mock_Popen.assert_called_once_with([
BROKER_CLIENT_PATH, 'publish',
'--consumer-app-version=2.0.1',
'--broker-base-url=http://localhost',
'--broker-base-url=http://localhost:9292',
'--broker-username=username',
'--broker-password=password',
'--broker-token=token',
'./TestConsumer-TestProvider.json'])

def test_git_tagged_publish(self):
broker = Broker(broker_base_url="http://localhost")
broker = Broker(broker_base_url="http://localhost:9292")

broker.publish("TestConsumer",
"2.0.1",
Expand All @@ -118,12 +118,12 @@ def test_git_tagged_publish(self):
self.mock_Popen.assert_called_once_with([
BROKER_CLIENT_PATH, 'publish',
'--consumer-app-version=2.0.1',
'--broker-base-url=http://localhost',
'--broker-base-url=http://localhost:9292',
'./TestConsumer-TestProvider.json',
'--tag-with-git-branch'])

def test_manual_tagged_publish(self):
broker = Broker(broker_base_url="http://localhost")
broker = Broker(broker_base_url="http://localhost:9292")

broker.publish("TestConsumer",
"2.0.1",
Expand All @@ -133,13 +133,13 @@ def test_manual_tagged_publish(self):
self.mock_Popen.assert_called_once_with([
BROKER_CLIENT_PATH, 'publish',
'--consumer-app-version=2.0.1',
'--broker-base-url=http://localhost',
'--broker-base-url=http://localhost:9292',
'./TestConsumer-TestProvider.json',
'-t', 'tag1',
'-t', 'tag2'])

def test_branch_publish(self):
broker = Broker(broker_base_url="http://localhost")
broker = Broker(broker_base_url="http://localhost:9292")

broker.publish("TestConsumer",
"2.0.1",
Expand All @@ -149,12 +149,12 @@ def test_branch_publish(self):
self.mock_Popen.assert_called_once_with([
BROKER_CLIENT_PATH, 'publish',
'--consumer-app-version=2.0.1',
'--broker-base-url=http://localhost',
'--broker-base-url=http://localhost:9292',
'./TestConsumer-TestProvider.json',
'--branch=consumer-branch'])

def test_build_url_publish(self):
broker = Broker(broker_base_url="http://localhost")
broker = Broker(broker_base_url="http://localhost:9292")

broker.publish("TestConsumer",
"2.0.1",
Expand All @@ -164,12 +164,12 @@ def test_build_url_publish(self):
self.mock_Popen.assert_called_once_with([
BROKER_CLIENT_PATH, 'publish',
'--consumer-app-version=2.0.1',
'--broker-base-url=http://localhost',
'--broker-base-url=http://localhost:9292',
'./TestConsumer-TestProvider.json',
'--build-url=http://ci'])

def test_auto_detect_version_properties_publish(self):
broker = Broker(broker_base_url="http://localhost")
broker = Broker(broker_base_url="http://localhost:9292")

broker.publish("TestConsumer",
"2.0.1",
Expand All @@ -179,6 +179,6 @@ def test_auto_detect_version_properties_publish(self):
self.mock_Popen.assert_called_once_with([
BROKER_CLIENT_PATH, 'publish',
'--consumer-app-version=2.0.1',
'--broker-base-url=http://localhost',
'--broker-base-url=http://localhost:9292',
'./TestConsumer-TestProvider.json',
'--auto-detect-version-properties'])
4 changes: 2 additions & 2 deletions tests/test_message_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def setUp(self):
self.options = {
'broker_username': "test",
'broker_password': "test",
'broker_url': "http://localhost",
'broker_url': "http://localhost:9292",
'publish_version': '3',
'publish_verification_results': False
}
Expand Down Expand Up @@ -65,7 +65,7 @@ def test_verify_with_broker(self, mock_verify_pacts):
assert mock_verify_pacts.call_count == 1
mock_verify_pacts.assert_called_with(False, None, broker_username="test",
broker_password="test",
broker_url="http://localhost",
broker_url="http://localhost:9292",
publish_version='3',
publish_verification_results=False)

Expand Down