|
18 | 18 | import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; |
19 | 19 | import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; |
20 | 20 | import static com.github.tomakehurst.wiremock.client.WireMock.verify; |
| 21 | +import static org.junit.Assert.assertEquals; |
21 | 22 |
|
22 | 23 | import com.github.tomakehurst.wiremock.junit.WireMockRule; |
23 | 24 | import io.kubernetes.client.openapi.ApiClient; |
@@ -61,6 +62,34 @@ public void testUrl() throws InterruptedException, IOException, ApiException { |
61 | 62 |
|
62 | 63 | verify( |
63 | 64 | getRequestedFor(urlPathEqualTo("/version/")) |
64 | | - .withHeader("Content-Type", equalTo("application/json"))); |
| 65 | + .withHeader("Content-Type", equalTo("application/json")) |
| 66 | + .withHeader("Accept", equalTo("application/json"))); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testFailure() throws InterruptedException, IOException, ApiException { |
| 71 | + |
| 72 | + wireMockRule.stubFor( |
| 73 | + get(urlPathEqualTo("/version/")) |
| 74 | + .willReturn( |
| 75 | + aResponse() |
| 76 | + .withStatus(401) |
| 77 | + .withHeader("Content-Type", "application/json") |
| 78 | + .withBody("{}"))); |
| 79 | + |
| 80 | + Version versionUtil = new Version(client); |
| 81 | + boolean thrown = false; |
| 82 | + try { |
| 83 | + VersionInfo versionInfo = versionUtil.getVersion(); |
| 84 | + } catch (ApiException ex) { |
| 85 | + assertEquals(401, ex.getCode()); |
| 86 | + thrown = true; |
| 87 | + } |
| 88 | + assertEquals(thrown, true); |
| 89 | + |
| 90 | + verify( |
| 91 | + getRequestedFor(urlPathEqualTo("/version/")) |
| 92 | + .withHeader("Content-Type", equalTo("application/json")) |
| 93 | + .withHeader("Accept", equalTo("application/json"))); |
65 | 94 | } |
66 | 95 | } |
0 commit comments