Skip to content

Commit

Permalink
fix: ensure pact dir exists
Browse files Browse the repository at this point in the history
Signed-off-by: JP-Ellis <[email protected]>
  • Loading branch information
JP-Ellis committed Nov 8, 2024
1 parent 10ac966 commit e16ad1a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/pact/message_pact.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import json
import os
from pathlib import Path
from subprocess import Popen
import warnings

Expand Down Expand Up @@ -176,16 +177,21 @@ def write_to_pact_file(self):
:rtype: int
"""
pact_dir = Path(self.pact_dir).resolve()
command = [
MESSAGE_PATH,
"update",
json.dumps(self._messages[0]),
"--pact-dir", self.pact_dir,
"--pact-dir", str(pact_dir),
f"--pact-specification-version={self.version}",
"--consumer", f"{self.consumer.name}",
"--provider", f"{self.provider.name}",
]

if not pact_dir.exists():
pact_dir.mkdir(parents=True)
elif not pact_dir.is_dir():
raise NotADirectoryError(f"{pact_dir} is not a directory")

Check warning on line 194 in src/pact/message_pact.py

View check run for this annotation

Codecov / codecov/patch

src/pact/message_pact.py#L194

Added line #L194 was not covered by tests
self._message_process = Popen(command)
self._message_process.wait()

Expand Down
5 changes: 3 additions & 2 deletions tests/test_message_pact.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import json
from pathlib import Path

from mock import patch
from unittest import TestCase
Expand Down Expand Up @@ -242,7 +243,7 @@ def setUp(self):

def test_call_pact_message_to_generate_pact_file(self):
target = MessagePact(
self.consumer, self.provider, pact_dir='/pacts',
self.consumer, self.provider, pact_dir='pacts',
version='3.0.0', file_write_mode='merge', publish_to_broker=True)

(target
Expand All @@ -260,7 +261,7 @@ def test_call_pact_message_to_generate_pact_file(self):
self.mock_Popen.assert_called_once_with([
MESSAGE_PATH, 'update',
json.dumps(target._messages[0]),
'--pact-dir', '/pacts',
'--pact-dir', str(Path("pacts").resolve()),
'--pact-specification-version=3.0.0',
'--consumer', 'TestConsumer',
'--provider', 'TestProvider',
Expand Down

0 comments on commit e16ad1a

Please sign in to comment.