Skip to content

Commit

Permalink
fix: include the consumer name in the selectors sent to the broker #1193
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Oct 1, 2020
1 parent 8d40c92 commit 358a76d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Expand Up @@ -68,7 +68,16 @@ data class ConsumerVersionSelector(
val latest: Boolean = true,
val consumer: String? = null
) {
fun toJson() = JsonValue.Object("tag" to Json.toJson(tag), "latest" to Json.toJson(latest))
fun toJson(): JsonValue {
val obj = JsonValue.Object("latest" to Json.toJson(latest))
if (tag.isNotEmpty()) {
obj.add("tag", Json.toJson(tag))
}
if (consumer.isNotEmpty()) {
obj.add("consumer", Json.toJson(consumer))
}
return obj
}
}

interface IPactBrokerClient {
Expand Down
@@ -0,0 +1,21 @@
package au.com.dius.pact.core.pactbroker

import spock.lang.Specification
import spock.lang.Unroll

class ConsumerVersionSelectorSpec extends Specification {

@Unroll
def 'convert to JSON'() {
expect:
new ConsumerVersionSelector(tag, latest, consumer).toJson().serialise() == json

where:

tag | latest | consumer | json
'A' | true | null | '{"latest":true,"tag":"A"}'
'A' | false | null | '{"latest":false,"tag":"A"}'
'A' | false | 'Bob' | '{"consumer":"Bob","latest":false,"tag":"A"}'
null | false | 'Bob' | '{"consumer":"Bob","latest":false}'
}
}

0 comments on commit 358a76d

Please sign in to comment.