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

Allow to merge with existing pact file #88

Closed
abendt opened this issue Apr 29, 2022 · 2 comments
Closed

Allow to merge with existing pact file #88

abendt opened this issue Apr 29, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@abendt
Copy link

abendt commented Apr 29, 2022

🗣 Context

We want to have pact tests in separate source files that describe interactions for the same consumer/provider

PactSwift seems to overwrite any existing pact file. It would be nice if there was an option that allows to merge with
an existing pact (similiar to the pact-jvm-consumer https://docs.pact.io/implementation_guides/jvm/consumer/junit#forcing-pact-files-to-be-overwritten-365)

💬 Narrative

Given an existing pact file for a specific consumer/provider
When running a pact consumer test for the same consumer/provider
I want the result of the second run to be merged into the existing pact file
So that i end up with one pact file describing all interactions

📝 Notes

🏗 Design

The pact-ffi interface int32_t pactffi_write_pact_file(int32_t mock_server_port, const char *directory, bool overwrite); already supports merge (by default) and overwriting a pact file.

  • Add a convenience init PactSwift.MockService.init(consumer: provider: scheme: writePactTo: overwrite:) with the optional overwrite argument set to false as to merge as a default,
  • Track the immutable state for overwrite in a private let (similar to pactsDirectory)
  • When creating a MockServer object when finalising the Pact tests (triggering pact-ffi to write the file) init it with overwrite parameter.
  • Access the immutable private let overwrite value in func dealing with pact-ffi writePactContractFile(port: completion:)
  • A new version of PactSwiftMockServer and a generated XCFramework binary needed to vend via SPM
  • A new version of PactSwift

✅ Acceptance Criteria

GIVEN ...
WHEN ...
THEN ...

🚫 Out of Scope

@abendt abendt added the enhancement New feature or request label Apr 29, 2022
@surpher
Copy link
Owner

surpher commented May 10, 2022

That's a good request. Thanks for raising it.
Indeed PactSwift is forcing an overwrite on each test run. pact-ffi already supports the merging of existing Pact files and the update to PactSwift and PactSwiftMockService should be an easy enough job. It just happens it needs code changes in two repos.

The Design part has been added to the issue and hopefully should be clear enough for someone to tackle it? Otherwise it will have to wait for a couple of weeks for me to pick it up.

In the mean time... The overwriting of Pact file should not keep you from keeping Pact tests for same consumer/provider in multiple files. You should be able to use inheritance and have a reference to your mockService singleton. You will still only end up only with the interactions for the tests you run. If you want all interactions written in the same file you need to run them all in one test run.

@surpher surpher self-assigned this May 31, 2022
@surpher
Copy link
Owner

surpher commented Jun 1, 2022

Available from PactSwift v0.12.1 with combination of PactSwiftMockServer v0.3.8.

@surpher surpher closed this as completed Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants