Skip to content

Commit 189cff7

Browse files
author
Shubh Bapna
committed
added test cases for delete label
1 parent 2e589ef commit 189cff7

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,43 @@ public void testKubectlLabelNamespacedResourceShouldWork() throws KubectlExcepti
7474
assertNotNull(labelledPod);
7575
}
7676

77+
@Test
78+
public void testKubectlDeleteLabelNamespacedResourceShouldWork() throws KubectlException {
79+
wireMockRule.stubFor(
80+
get(urlPathEqualTo("/api/v1/namespaces/default/pods/foo"))
81+
.willReturn(
82+
aResponse()
83+
.withStatus(200)
84+
.withBody("{\"metadata\":{\"name\":\"foo\",\"namespace\":\"default\"}}")));
85+
wireMockRule.stubFor(
86+
put(urlPathEqualTo("/api/v1/namespaces/default/pods/foo"))
87+
.willReturn(
88+
aResponse()
89+
.withStatus(200)
90+
.withBody("{\"metadata\":{\"name\":\"foo\",\"namespace\":\"default\"}}")));
91+
92+
Kubectl.label(V1Pod.class)
93+
.apiClient(apiClient)
94+
.skipDiscovery()
95+
.namespace("default")
96+
.name("foo")
97+
.addLabel("k1", "v1")
98+
.execute();
99+
100+
V1Pod unlabelledPod =
101+
Kubectl.label(V1Pod.class)
102+
.apiClient(apiClient)
103+
.skipDiscovery()
104+
.namespace("default")
105+
.name("foo")
106+
.deleteLabel("k1")
107+
.execute();
108+
109+
wireMockRule.verify(2, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")));
110+
wireMockRule.verify(2, putRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")));
111+
assertNotNull(unlabelledPod);
112+
}
113+
77114
@Test
78115
public void testKubectlLabelNamespacedResourceReceiveForbiddenShouldThrowException()
79116
throws KubectlException {
@@ -123,6 +160,35 @@ public void testKubectlLabelClusterResourceShouldWork() throws KubectlException
123160
assertNotNull(labelledNode);
124161
}
125162

163+
@Test
164+
public void testKubectlDeleteLabelClusterResourceShouldWork() throws KubectlException {
165+
wireMockRule.stubFor(
166+
get(urlPathEqualTo("/api/v1/nodes/foo"))
167+
.willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"foo\"}}")));
168+
wireMockRule.stubFor(
169+
put(urlPathEqualTo("/api/v1/nodes/foo"))
170+
.willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"foo\"}}")));
171+
172+
Kubectl.label(V1Node.class)
173+
.apiClient(apiClient)
174+
.skipDiscovery()
175+
.name("foo")
176+
.addLabel("k1", "v1")
177+
.execute();
178+
179+
V1Node unlabelledNode =
180+
Kubectl.label(V1Node.class)
181+
.apiClient(apiClient)
182+
.skipDiscovery()
183+
.name("foo")
184+
.deleteLabel("k1")
185+
.execute();
186+
wireMockRule.verify(2, getRequestedFor(urlPathEqualTo("/api/v1/nodes/foo")));
187+
wireMockRule.verify(2, putRequestedFor(urlPathEqualTo("/api/v1/nodes/foo")));
188+
assertNotNull(unlabelledNode);
189+
}
190+
191+
126192
@Test
127193
public void testKubectlLabelClusterResourceReceiveForbiddenShouldThrowException()
128194
throws KubectlException {

0 commit comments

Comments
 (0)