|
16 | 16 | package com.netflix.spinnaker.igor.gitlabci.service
|
17 | 17 |
|
18 | 18 | import com.netflix.spinnaker.fiat.model.resources.Permissions
|
19 |
| -import com.netflix.spinnaker.igor.config.GitlabCiProperties |
20 | 19 | import com.netflix.spinnaker.igor.config.GitlabCiProperties.GitlabCiHost
|
21 |
| -import com.netflix.spinnaker.igor.gitlabci.client.GitlabApiCannedResponses |
22 | 20 | import com.netflix.spinnaker.igor.gitlabci.client.GitlabCiClient
|
| 21 | +import com.netflix.spinnaker.igor.gitlabci.client.model.Job |
23 | 22 | import com.netflix.spinnaker.igor.gitlabci.client.model.Pipeline
|
24 | 23 | import com.netflix.spinnaker.igor.gitlabci.client.model.Project
|
| 24 | +import com.netflix.spinnaker.igor.helpers.TestUtils |
| 25 | +import com.netflix.spinnaker.igor.jenkins.client.model.Build |
| 26 | +import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException |
| 27 | +import okhttp3.MediaType |
| 28 | +import okhttp3.ResponseBody |
25 | 29 | import retrofit2.mock.Calls
|
26 | 30 | import spock.lang.Shared
|
27 | 31 | import spock.lang.Specification
|
| 32 | +import spock.lang.Unroll |
28 | 33 |
|
29 | 34 | class GitlabCiServiceSpec extends Specification {
|
30 | 35 | @Shared
|
@@ -94,4 +99,76 @@ class GitlabCiServiceSpec extends Specification {
|
94 | 99 |
|
95 | 100 | 1 * client.getPipelineSummaries(_, _) >> Calls.response([])
|
96 | 101 | }
|
| 102 | + |
| 103 | + @Unroll |
| 104 | + def "getBuildProperties retries on transient failure"() { |
| 105 | + given: |
| 106 | + final String PROJECT_ID = "13" |
| 107 | + final int PIPELINE_ID = 3 |
| 108 | + final int JOB_ID = 1 |
| 109 | + |
| 110 | + def build = new Build(number: PIPELINE_ID, duration: 0L) |
| 111 | + def testPipeline = new Pipeline(id: PIPELINE_ID) |
| 112 | + def testJob = new Job(pipeline: testPipeline, id: JOB_ID) |
| 113 | + def badGatewayError = TestUtils.makeSpinnakerHttpException("http://test.net", 502, ResponseBody.create("{}", MediaType.parse("application/json"))) |
| 114 | + def jobLog = ResponseBody.create("SPINNAKER_PROPERTY_TEST=1",MediaType.parse("application/text")) |
| 115 | + |
| 116 | + when: |
| 117 | + def properties = service.getBuildProperties(PROJECT_ID, build.genericBuild(PROJECT_ID), "test.properties") |
| 118 | + |
| 119 | + then: |
| 120 | + 2 * client.getPipeline(PROJECT_ID, PIPELINE_ID) >> { throw badGatewayError } >> Calls.response(testPipeline) |
| 121 | + 1 * client.getJobs(PROJECT_ID, PIPELINE_ID) >> Calls.response([testJob]) |
| 122 | + 1 * client.getBridges(PROJECT_ID, PIPELINE_ID) >> Calls.response([]) |
| 123 | + 1 * client.getJobLog(PROJECT_ID, JOB_ID) >> Calls.response(jobLog) |
| 124 | + |
| 125 | + properties == [test: "1"] |
| 126 | + } |
| 127 | + |
| 128 | + @Unroll |
| 129 | + def "getBuildProperties retries on 404"() { |
| 130 | + given: |
| 131 | + final String PROJECT_ID = "13" |
| 132 | + final int PIPELINE_ID = 3 |
| 133 | + final int JOB_ID = 1 |
| 134 | + |
| 135 | + def build = new Build(number: PIPELINE_ID, duration: 0L) |
| 136 | + def testPipeline = new Pipeline(id: PIPELINE_ID) |
| 137 | + def testJob = new Job(pipeline: testPipeline, id: JOB_ID) |
| 138 | + def notFoundError = TestUtils.makeSpinnakerHttpException("http://test.net", 404, ResponseBody.create("not found", MediaType.parse("application/text"))) |
| 139 | + def jobLog = ResponseBody.create("SPINNAKER_PROPERTY_TEST=1",MediaType.parse("application/text")) |
| 140 | + |
| 141 | + when: |
| 142 | + def properties = service.getBuildProperties(PROJECT_ID, build.genericBuild(PROJECT_ID), "test.properties") |
| 143 | + |
| 144 | + then: |
| 145 | + 2 * client.getPipeline(PROJECT_ID, PIPELINE_ID) >> { throw notFoundError } >> Calls.response(testPipeline) |
| 146 | + 1 * client.getJobs(PROJECT_ID, PIPELINE_ID) >> Calls.response([testJob]) |
| 147 | + 1 * client.getBridges(PROJECT_ID, PIPELINE_ID) >> Calls.response([]) |
| 148 | + 1 * client.getJobLog(PROJECT_ID, JOB_ID) >> Calls.response(jobLog) |
| 149 | + |
| 150 | + properties == [test: "1"] |
| 151 | + } |
| 152 | + |
| 153 | + @Unroll |
| 154 | + def "getBuildProperties does not retry on 400"() { |
| 155 | + given: |
| 156 | + final String PROJECT_ID = "13" |
| 157 | + final int PIPELINE_ID = 3 |
| 158 | + final int JOB_ID = 1 |
| 159 | + |
| 160 | + def build = new Build(number: PIPELINE_ID, duration: 0L) |
| 161 | + def badRequestError = TestUtils.makeSpinnakerHttpException("http://test.net", 400, ResponseBody.create("bad request", MediaType.parse("application/text"))) |
| 162 | + |
| 163 | + when: |
| 164 | + service.getBuildProperties(PROJECT_ID, build.genericBuild(PROJECT_ID), "test.properties") |
| 165 | + |
| 166 | + then: |
| 167 | + 1 * client.getPipeline(PROJECT_ID, PIPELINE_ID) >> { throw badRequestError } |
| 168 | + 0 * client.getJobs(PROJECT_ID, PIPELINE_ID) |
| 169 | + 0 * client.getBridges(PROJECT_ID, PIPELINE_ID) |
| 170 | + 0 * client.getJobLog(PROJECT_ID, JOB_ID) |
| 171 | + |
| 172 | + thrown SpinnakerHttpException |
| 173 | + } |
97 | 174 | }
|
0 commit comments