Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.

Commit 0f7a37d

Browse files
alice485alice garcia
andauthored
refactor(retrofit): removed last few remaining references to retrofit1 (#2125)
Co-authored-by: alice garcia <alice_garcia@homedepot.com>
1 parent 8632c0c commit 0f7a37d

File tree

4 files changed

+39
-24
lines changed

4 files changed

+39
-24
lines changed

keel-igor/src/test/kotlin/com/netflix/spinnaker/keel/services/ArtifactMetadataServiceTests.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import dev.minutest.rootContext
1818
import io.mockk.coEvery
1919
import io.mockk.mockk
2020
import kotlinx.coroutines.runBlocking
21-
import retrofit.RetrofitError
22-
import retrofit.client.Response
21+
import okhttp3.MediaType.Companion.toMediaTypeOrNull
22+
import okhttp3.ResponseBody.Companion.toResponseBody
23+
import retrofit2.HttpException
2324
import strikt.api.expectCatching
2425
import strikt.api.expectThat
2526
import strikt.assertions.isEqualTo
@@ -141,24 +142,22 @@ class ArtifactMetadataServiceTests : JUnit5Minutests {
141142
}
142143

143144
context("with HTTP error coming from igor") {
144-
val retrofitError = RetrofitError.httpError(
145-
"http://igor",
146-
Response("http://igor", 404, "not found", emptyList(), null),
147-
null, null
145+
val notFoundError = HttpException(
146+
retrofit2.Response.error<Any>(404, "".toResponseBody("application/json".toMediaTypeOrNull()))
148147
)
149148

150149
before {
151150
coEvery {
152151
buildService.getArtifactMetadata(commitId = any(), buildNumber = any(), completionStatus = any())
153-
} throws retrofitError
152+
} throws notFoundError
154153
}
155154

156155
test("throw an http error from fallback method") {
157156
expectCatching {
158157
artifactMetadataService.getArtifactMetadata("1", "a15p0")
159158
}
160159
.isFailure()
161-
.isEqualTo(retrofitError)
160+
.isEqualTo(notFoundError)
162161
}
163162
}
164163
}

keel-igor/src/test/kotlin/com/netflix/spinnaker/keel/services/DeliveryConfigImporterTests.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import com.netflix.spinnaker.keel.test.deliveryConfig
1818
import dev.minutest.junit.JUnit5Minutests
1919
import dev.minutest.rootContext
2020
import io.mockk.mockk
21-
import retrofit.RetrofitError
22-
import retrofit.client.Response
21+
import okhttp3.MediaType.Companion.toMediaTypeOrNull
22+
import okhttp3.ResponseBody.Companion.toResponseBody
23+
import retrofit2.HttpException
2324
import strikt.api.expectCatching
2425
import strikt.api.expectThat
2526
import strikt.assertions.all
@@ -121,16 +122,14 @@ class DeliveryConfigImporterTests : JUnit5Minutests {
121122
}
122123

123124
context("with HTTP error retrieving delivery config from igor") {
124-
val retrofitError = RetrofitError.httpError(
125-
"http://igor",
126-
Response("http://igor", 404, "not found", emptyList(), null),
127-
null, null
125+
val notFoundError = HttpException(
126+
retrofit2.Response.error<Any>(404, "".toResponseBody("application/yaml".toMediaTypeOrNull()))
128127
)
129128

130129
before {
131130
every {
132131
scmService.getDeliveryConfigManifest("stash", "proj", "repo", "spinnaker.yml", any(), any())
133-
} throws retrofitError
132+
} throws notFoundError
134133
}
135134

136135
test("bubbles up HTTP error") {
@@ -144,7 +143,7 @@ class DeliveryConfigImporterTests : JUnit5Minutests {
144143
)
145144
}
146145
.isFailure()
147-
.isEqualTo(retrofitError)
146+
.isEqualTo(notFoundError)
148147
}
149148
}
150149

keel-web/keel-web.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ dependencies {
6363
testImplementation(project(":keel-clouddriver"))
6464
testImplementation("io.strikt:strikt-jackson")
6565
testImplementation("com.fasterxml.jackson.module:jackson-module-kotlin")
66+
testImplementation("io.spinnaker.kork:kork-retrofit")
6667
testImplementation("io.spinnaker.kork:kork-security")
6768
testImplementation("com.squareup.okhttp3:mockwebserver")
6869
testImplementation("org.testcontainers:mysql:${testContainersVersion}")

keel-web/src/test/kotlin/com/netflix/spinnaker/keel/rest/DeliveryConfigControllerTests.kt

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ import com.netflix.spinnaker.keel.persistence.DismissibleNotificationRepository
2727
import com.netflix.spinnaker.keel.persistence.KeelRepository
2828
import com.netflix.spinnaker.keel.persistence.NoDeliveryConfigForApplication
2929
import com.netflix.spinnaker.keel.persistence.NoSuchDeliveryConfigName
30+
import com.netflix.spinnaker.keel.retrofit.InstrumentedJacksonConverter
3031
import com.netflix.spinnaker.keel.spring.test.MockEurekaConfiguration
3132
import com.netflix.spinnaker.keel.test.DummyResourceSpec
3233
import com.netflix.spinnaker.keel.test.TEST_API_V1
3334
import com.netflix.spinnaker.keel.yaml.APPLICATION_YAML
35+
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException
3436
import com.ninjasquad.springmockk.MockkBean
3537
import dev.minutest.junit.JUnit5Minutests
3638
import dev.minutest.rootContext
@@ -41,6 +43,10 @@ import io.mockk.coVerify
4143
import io.mockk.every
4244
import io.mockk.just
4345
import io.mockk.verify
46+
import okhttp3.MediaType.Companion.toMediaTypeOrNull
47+
import okhttp3.Protocol
48+
import okhttp3.Request
49+
import okhttp3.ResponseBody.Companion.toResponseBody
4450
import org.springframework.beans.factory.annotation.Autowired
4551
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
4652
import org.springframework.boot.test.context.SpringBootTest
@@ -54,8 +60,8 @@ import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get
5460
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
5561
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.content
5662
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
57-
import retrofit.RetrofitError
58-
import retrofit.client.Response
63+
import retrofit2.Response
64+
import retrofit2.Retrofit
5965
import strikt.api.expectThat
6066
import strikt.jackson.at
6167
import strikt.jackson.isMissing
@@ -454,16 +460,26 @@ internal class DeliveryConfigControllerTests
454460
}
455461

456462
context("when manifest retrieval fails") {
457-
val retrofitError = RetrofitError.httpError(
458-
"http://igor",
459-
Response("http://igor", 404, "not found", emptyList(), null),
460-
null, null
461-
)
463+
val ok3Resp =
464+
okhttp3.Response.Builder()
465+
.code(404)
466+
.message("not found")
467+
.protocol(Protocol.HTTP_1_1)
468+
.request(Request.Builder().url("http://igor/").build())
469+
.build()
470+
471+
val retrofit =
472+
Retrofit.Builder()
473+
.baseUrl("http://igor/")
474+
.addConverterFactory(InstrumentedJacksonConverter.Factory("Igor", ObjectMapper()))
475+
.build()
476+
477+
val notFoundError = SpinnakerHttpException(Response.error<Any>("".toResponseBody("application/yaml".toMediaTypeOrNull()), ok3Resp), retrofit)
462478

463479
before {
464480
every {
465481
importer.import("stash", "proj", "repo", "spinnaker.yml", "refs/heads/master")
466-
} throws retrofitError
482+
} throws notFoundError
467483
}
468484

469485
test("the error from the downstream service is returned") {

0 commit comments

Comments
 (0)