Skip to content

Commit

Permalink
fix: pass consumer.pending through when validating an async message i…
Browse files Browse the repository at this point in the history
…nteraction #1573
  • Loading branch information
uglyog committed Jul 26, 2022
1 parent fe762dc commit c085da6
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ data class PactVerificationContext @JvmOverloads constructor(
}
} else {
return listOf(verifier!!.verifyResponseByInvokingProviderMethods(providerInfo, consumer, interaction,
interaction.description, mutableMapOf(), false))
interaction.description, mutableMapOf(), consumer.pending))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ import au.com.dius.pact.core.model.Interaction
import au.com.dius.pact.core.model.Request
import au.com.dius.pact.core.model.RequestResponseInteraction
import au.com.dius.pact.core.model.Response
import au.com.dius.pact.core.model.messaging.Message
import au.com.dius.pact.core.support.expressions.ValueResolver
import au.com.dius.pact.provider.ConsumerInfo
import au.com.dius.pact.provider.IConsumerInfo
import au.com.dius.pact.provider.IProviderInfo
import au.com.dius.pact.provider.IProviderVerifier
import au.com.dius.pact.provider.PactVerification
import au.com.dius.pact.provider.VerificationFailureType
import au.com.dius.pact.provider.VerificationResult
import org.junit.jupiter.api.extension.ExtensionContext
import spock.lang.Issue
import spock.lang.Specification

@SuppressWarnings('UnnecessaryGetter')
class PactVerificationContextSpec extends Specification {

@SuppressWarnings('UnnecessaryGetter')
def 'sets the test result to an error result if the test fails with an exception'() {
given:
PactVerificationContext context
Expand Down Expand Up @@ -57,7 +60,6 @@ class PactVerificationContextSpec extends Specification {
context.testExecutionResult[0].failures['12345'][0] instanceof VerificationFailureType.ExceptionFailure
}

@SuppressWarnings('UnnecessaryGetter')
def 'only throw an exception if there are non-pending failures'() {
given:
PactVerificationContext context
Expand Down Expand Up @@ -100,4 +102,45 @@ class PactVerificationContextSpec extends Specification {
context.testExecutionResult[0].failures.size() == 1
context.testExecutionResult[0].failures['12345'][0] instanceof VerificationFailureType.ExceptionFailure
}

@Issue('#1573')
def 'support pending flag with async message interactions'() {
given:
PactVerificationContext context
ExtensionContext.Store store = Stub {
get(_) >> { args ->
if (args[0] == 'interactionContext') {
context
}
}
}
ExtensionContext extContext = Stub {
getStore(_) >> store
}
TestTarget target = Stub {
executeInteraction(_, _) >> { throw new IOException('Boom!') }
}
IProviderVerifier verifier = Mock()
ValueResolver valueResolver = Stub()
IProviderInfo provider = Stub {
getName() >> 'Stub'
getVerificationType() >> PactVerification.ANNOTATED_METHOD
}
IConsumerInfo consumer = Mock(IConsumerInfo) {
getName() >> 'test'
getPending() >> true
}
Interaction interaction = new Message('Test Interaction')
List<VerificationResult> testResults = []

context = new PactVerificationContext(store, extContext, target, verifier, valueResolver,
provider, consumer, interaction, testResults)

when:
context.verifyInteraction()

then:
1 * verifier.verifyResponseByInvokingProviderMethods(provider, consumer, interaction,
interaction.description, [:], true) >> new VerificationResult.Ok()
}
}

0 comments on commit c085da6

Please sign in to comment.