|
25 | 25 | import io.kubernetes.client.openapi.ApiClient;
|
26 | 26 | import io.kubernetes.client.openapi.models.V1DaemonSet;
|
27 | 27 | import io.kubernetes.client.openapi.models.V1Deployment;
|
| 28 | +import io.kubernetes.client.openapi.models.V1StatefulSet; |
28 | 29 | import io.kubernetes.client.util.ClientBuilder;
|
29 | 30 | import java.io.IOException;
|
30 | 31 | import java.nio.file.Files;
|
@@ -58,6 +59,15 @@ public class KubectlRolloutHistoryTest {
|
58 | 59 | .getResource("daemonset-controllerrevision-list.json")
|
59 | 60 | .getPath();
|
60 | 61 |
|
| 62 | + private static final String STATEFUL_SET = |
| 63 | + KubectlRolloutHistoryTest.class.getClassLoader().getResource("statefulset.json").getPath(); |
| 64 | + |
| 65 | + private static final String STATEFUL_SET_CONTROLLER_REVISION_LIST = |
| 66 | + KubectlRolloutHistoryTest.class |
| 67 | + .getClassLoader() |
| 68 | + .getResource("statefulset-controllerrevision-list.json") |
| 69 | + .getPath(); |
| 70 | + |
61 | 71 | @Before
|
62 | 72 | public void setup() throws IOException {
|
63 | 73 | apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
|
@@ -187,6 +197,73 @@ public void testKubectlRolloutHistoryDaemonSetWithRevisionShouldWork()
|
187 | 197 | Assert.assertNotNull(rolloutHistory.getTemplate());
|
188 | 198 | }
|
189 | 199 |
|
| 200 | + @Test |
| 201 | + public void testKubectlRolloutHistoryStatefulSetShouldWork() |
| 202 | + throws KubectlException, IOException { |
| 203 | + wireMockRule.stubFor( |
| 204 | + get(urlPathEqualTo("/apis/apps/v1/namespaces/default/statefulsets/foo")) |
| 205 | + .willReturn( |
| 206 | + aResponse() |
| 207 | + .withStatus(200) |
| 208 | + .withBody(new String(Files.readAllBytes(Paths.get(STATEFUL_SET)))))); |
| 209 | + wireMockRule.stubFor( |
| 210 | + get(urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions")) |
| 211 | + .willReturn( |
| 212 | + aResponse() |
| 213 | + .withStatus(200) |
| 214 | + .withBody( |
| 215 | + new String( |
| 216 | + Files.readAllBytes( |
| 217 | + Paths.get(STATEFUL_SET_CONTROLLER_REVISION_LIST)))))); |
| 218 | + KubectlRolloutHistory<V1StatefulSet> rolloutHistory = |
| 219 | + Kubectl.rolloutHistory(V1StatefulSet.class) |
| 220 | + .apiClient(apiClient) |
| 221 | + .name("foo") |
| 222 | + .namespace("default"); |
| 223 | + rolloutHistory.execute(); |
| 224 | + wireMockRule.verify( |
| 225 | + 1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/statefulsets/foo")))); |
| 226 | + wireMockRule.verify( |
| 227 | + 1, |
| 228 | + getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions"))) |
| 229 | + .withQueryParam("labelSelector", new EqualToPattern("app = bar"))); |
| 230 | + Assert.assertEquals(3, rolloutHistory.getHistories().size()); |
| 231 | + } |
| 232 | + |
| 233 | + @Test |
| 234 | + public void testKubectlRolloutHistoryStatefulSetWithRevisionShouldWork() |
| 235 | + throws KubectlException, IOException { |
| 236 | + wireMockRule.stubFor( |
| 237 | + get(urlPathEqualTo("/apis/apps/v1/namespaces/default/statefulsets/foo")) |
| 238 | + .willReturn( |
| 239 | + aResponse() |
| 240 | + .withStatus(200) |
| 241 | + .withBody(new String(Files.readAllBytes(Paths.get(STATEFUL_SET)))))); |
| 242 | + wireMockRule.stubFor( |
| 243 | + get(urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions")) |
| 244 | + .willReturn( |
| 245 | + aResponse() |
| 246 | + .withStatus(200) |
| 247 | + .withBody( |
| 248 | + new String( |
| 249 | + Files.readAllBytes( |
| 250 | + Paths.get(STATEFUL_SET_CONTROLLER_REVISION_LIST)))))); |
| 251 | + KubectlRolloutHistory<V1StatefulSet> rolloutHistory = |
| 252 | + Kubectl.rolloutHistory(V1StatefulSet.class) |
| 253 | + .apiClient(apiClient) |
| 254 | + .name("foo") |
| 255 | + .namespace("default") |
| 256 | + .revision(2); |
| 257 | + rolloutHistory.execute(); |
| 258 | + wireMockRule.verify( |
| 259 | + 1, getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/statefulsets/foo")))); |
| 260 | + wireMockRule.verify( |
| 261 | + 1, |
| 262 | + getRequestedFor((urlPathEqualTo("/apis/apps/v1/namespaces/default/controllerrevisions"))) |
| 263 | + .withQueryParam("labelSelector", new EqualToPattern("app = bar"))); |
| 264 | + Assert.assertNotNull(rolloutHistory.getTemplate()); |
| 265 | + } |
| 266 | + |
190 | 267 | @Test
|
191 | 268 | public void testKubectlRolloutHistoryWithInvalidRevisionShouldThrow() throws IOException {
|
192 | 269 | wireMockRule.stubFor(
|
|
0 commit comments