Skip to content

Commit

Permalink
fix: MockServerURLGenerator was not combining URL fragments correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rholshausen committed May 30, 2023
1 parent b369fec commit 7e8d7fc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package au.com.dius.pact.core.model.generators

import au.com.dius.pact.core.model.PactSpecVersion
import au.com.dius.pact.core.model.matchingrules.MatchingRuleCategory
import au.com.dius.pact.core.support.HttpClientUtils.buildUrl
import au.com.dius.pact.core.support.Json
import au.com.dius.pact.core.support.Result
import au.com.dius.pact.core.support.expressions.DataType
Expand Down Expand Up @@ -563,11 +564,7 @@ data class MockServerURLGenerator(
val regex = Regex(regex)
val match = regex.matchEntire(example)
if (match != null) {
if (href.endsWith('/')) {
href + match.groupValues[1]
} else {
href + "/" + match.groupValues[1]
}
buildUrl(href, match.groupValues[1]).toString()
} else {
logger.error {
"MockServerURL: can not generate a value as the regex did not match the example, " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package au.com.dius.pact.core.model.generators
import spock.lang.Specification
import spock.lang.Unroll

@SuppressWarnings('LineLength')
class MockServerURLGeneratorSpec extends Specification {

@SuppressWarnings('LineLength')
@Unroll
def 'generate returns null when #desc'() {
expect:
Expand Down Expand Up @@ -34,4 +34,12 @@ class MockServerURLGeneratorSpec extends Specification {
[mockServer: [href: 'http://mockserver/']]
]
}

def 'examples from Pact Compatability Suite'() {
expect:
new MockServerURLGenerator('http://localhost:9876/pacts/provider/{provider}/for-verification',
'.*(\\/\\Qpacts\\E\\/\\Qprovider\\E\\/\\Q{provider}\\E\\/\\Qfor-verification\\E)$')
.generate([mockServer: [href: 'http://localhost:40955']], null) ==
'http://localhost:40955/pacts/provider/%7Bprovider%7D/for-verification'
}
}

0 comments on commit 7e8d7fc

Please sign in to comment.