Skip to content

Commit 1a0da95

Browse files
committed
test : kubectl rollout history for stafefulset
1 parent 6e1b22f commit 1a0da95

File tree

3 files changed

+766
-0
lines changed

3 files changed

+766
-0
lines changed

extended/src/test/java/io/kubernetes/client/extended/kubectl/KubectlRolloutHistoryTest.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.kubernetes.client.openapi.ApiClient;
2626
import io.kubernetes.client.openapi.models.V1DaemonSet;
2727
import io.kubernetes.client.openapi.models.V1Deployment;
28+
import io.kubernetes.client.openapi.models.V1StatefulSet;
2829
import io.kubernetes.client.util.ClientBuilder;
2930
import java.io.IOException;
3031
import java.nio.file.Files;
@@ -58,6 +59,15 @@ public class KubectlRolloutHistoryTest {
5859
.getResource("daemonset-controllerrevision-list.json")
5960
.getPath();
6061

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+
6171
@Before
6272
public void setup() throws IOException {
6373
apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
@@ -187,6 +197,73 @@ public void testKubectlRolloutHistoryDaemonSetWithRevisionShouldWork()
187197
Assert.assertNotNull(rolloutHistory.getTemplate());
188198
}
189199

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+
190267
@Test
191268
public void testKubectlRolloutHistoryWithInvalidRevisionShouldThrow() throws IOException {
192269
wireMockRule.stubFor(

0 commit comments

Comments
 (0)