Skip to content

Separate Pact providers generated files contain all the pacts #98

@treatwell-ignasurbonas

Description

@treatwell-ignasurbonas

General
Setting different providers in same tests run (provider when creating MockServer instance) doesn't generate correct output (pact json files). All the pacts are generated for every provider file. This is an issue because we need to generate (and later upload) separate pacts files for different providers.

Example Issue
There are two providers: provider1 and provider2. MockService instance is created for each pact test. Provider for each test is set in initialiser:

public init(
    provider: String,
    consumer: String,
    pactVerificationService: PactVerificationService,
    errorReporter: ErrorReporter
  )

in test it looks:

class Pact1Tests: XCTestCase {
  func testPact1() {
    let mockServer = MockService(
        provider: "provider1",
        consumer: "consumer",
        pactVerificationService: PactVerificationService(url: <url>, port: 1234),
        errorReporter: Errors()
    )
    ...
  }
}

Remark: if you do it in override func setUp() - issue is still there.

After all tests finished, two pact files are generated: consumer-provider1.json and consumer-provider2.json.
If generated file is opened, you can see that all the tests, even if created MockServer instance for specific test had different provider name, are in that json.

Workaround
If you run tests separately for just provider1 and when just for provider2 (e.g. using test plans) files are generated correctly.

Summary
Probably the issue is with provider parameter propagation and file generation.

I hope this information is enough. I can try to provide more info if needed.

P.S. when we run pact ruby mock server we do not specify consumer and provider as we do it in code when we are creating MockServer instance.
pact-mock-service start --pact-specification-version $PACT_SPEC_VERSION --log $LOG --pact-dir $PACTS -p $PORT

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions