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

PactVerificationSpringProvider not respecting spring properties (and potential solution proposed) #1572

Open
scrooloose opened this issue Jun 14, 2022 · 0 comments
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@scrooloose
Copy link

The issue

I am seeing this in my logs:

Skipping publishing of verification results as it has been disabled (pact.verifier.publishResults is not 'true'

However, I have this in my testing applications.properties file:

# in my application.properties for testing
pact.verifier.publishResults=true

And I am using the PactVerificationSpringProvider junit extension - so I would expect my properties file to be used:

// my (very simplified) contract test runner class

@PactBroker(
    url = "https://my-pact-broker.example.com",
    consumerVersionSelectors = [VersionSelector(tag = "master")],
)
class MyContractTestRunner {
    @TestTemplate
    @ExtendWith(PactVerificationSpringProvider::class) // note that we use the spring provider
    fun pactVerificationTestTemplate(context: PactVerificationContext) {
         context.verifyInteraction()
    }
}

The fix (pretty sure)

In PactVerificationExtension we do not pass the ValueResolver in to the PactVerificationContext when we construct it - so it defaults to SystemPropertyResolver. One of the main functions of PactVerificationSpringProvider is to set up a SpringEnvironmentResolver instead of a SystemPropertyResolver so that spring property files are used.

I believe this can be fixed quite trivially i.e.

class PactVerificationExtension {
  // ...

  override fun beforeEach(context: ExtensionContext) {
    val store = context.getStore(namespace)
    val pending = interaction.isV4() && interaction.asV4Interaction().pending ||
      pactSource is BrokerUrlSource && pactSource.result?.pending == true

    // change this
    // val verificationContext = PactVerificationContext(store, context,
    //  consumer = ConsumerInfo(pact.consumer.name, pactSource = pactSource, pending = pending),
    //  interaction = interaction, providerInfo = ProviderInfo(serviceName))

    // to this, which includes "valueResolver"
    val verificationContext = PactVerificationContext(
      store,
      context,
      consumer = ConsumerInfo(pact.consumer.name, pactSource = pactSource, pending = pending),
      interaction = interaction, providerInfo = ProviderInfo(serviceName),
      valueResolver = propertyResolver, // <--- added
    )


    store.put("interactionContext", verificationContext)
  }

  // ...
rholshausen pushed a commit that referenced this issue Jul 26, 2022
@rholshausen rholshausen added the bug Indicates an unexpected problem or unintended behavior label Jul 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants