Skip to content

Commit

Permalink
fix: PactBrokerClient throws index-out-of-bounds when can-i-deploy is…
Browse files Browse the repository at this point in the history
… called for a new tag #1814
  • Loading branch information
rholshausen committed Jul 12, 2024
1 parent 5a18fa4 commit c8cf331
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ open class PactBrokerClient(
is Ok<JsonValue> -> {
val summary = result.value["summary"].asObject()!!
val matrix = result.value["matrix"]
val verificationResultUrl = if (matrix.isArray) {
val verificationResultUrl = if (matrix.isArray && matrix.size() > 0) {
matrix.asArray()
?.get(0)?.asObject()
?.get("verificationResult")?.asObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -792,4 +792,39 @@ class PactBrokerClientSpec extends Specification {
result.ok
result.verificationResultUrl == 'verificationResultUrl'
}

@Issue('#1814')
def 'can-i-deploy - handles an empty matrix response'() {
given:
def halClient = Mock(IHalClient)
def config = new PactBrokerClientConfig(10, 0)
PactBrokerClient client = Spy(PactBrokerClient, constructorArgs: ['baseUrl', [:], config]) {
newHalClient() >> halClient
}
def json = JsonParser.parseString('''
|{
| "summary": {
| "deployable": true,
| "reason": "There are no missing dependencies",
| "success": 0,
| "failed": 0,
| "unknown": 0
| },
| "notices": [
| {
| "type": "success",
| "text": "There are no missing dependencies"
| }
| ],
| "matrix": []
|}'''.stripMargin())

when:
def result = client.canIDeploy('test', '1.2.3', new Latest.UseLatest(true), '')

then:
1 * halClient.getJson(_, _) >> new Ok(json)
result.ok
!result.verificationResultUrl
}
}

0 comments on commit c8cf331

Please sign in to comment.