Skip to content

Commit 6683005

Browse files
author
Shubh Bapna
committed
fixed test cases and bug
1 parent 037e699 commit 6683005

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

extended/src/main/java/io/kubernetes/client/extended/kubectl/KubectlLabel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public KubectlLabel<ApiType> addLabel(String key, String value) {
3838
}
3939

4040
public KubectlLabel<ApiType> deleteLabel(String key) {
41-
this.addingLabels.put(key, null);
41+
this.addingLabels.put(key, "null");
4242
return this;
4343
}
4444

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,14 @@ public void testKubectlDeleteLabelNamespacedResourceShouldWork() throws KubectlE
8989
.withBody("{\"metadata\":{\"name\":\"foo\",\"namespace\":\"default\"}}")));
9090
wireMockRule.stubFor(
9191
put(urlPathEqualTo("/api/v1/namespaces/default/pods/foo"))
92+
.withRequestBody(
93+
matchingJsonPath(
94+
"$.metadata.labels", equalToJson("{ \"k1\": \"null\" }")))
9295
.willReturn(
9396
aResponse()
9497
.withStatus(200)
9598
.withBody("{\"metadata\":{\"name\":\"foo\",\"namespace\":\"default\"}}")));
9699

97-
Kubectl.label(V1Pod.class)
98-
.apiClient(apiClient)
99-
.skipDiscovery()
100-
.namespace("default")
101-
.name("foo")
102-
.addLabel("k1", "v1")
103-
.execute();
104-
105100
V1Pod unlabelledPod =
106101
Kubectl.label(V1Pod.class)
107102
.apiClient(apiClient)
@@ -111,8 +106,8 @@ public void testKubectlDeleteLabelNamespacedResourceShouldWork() throws KubectlE
111106
.deleteLabel("k1")
112107
.execute();
113108

114-
wireMockRule.verify(2, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")));
115-
wireMockRule.verify(2, putRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")));
109+
wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")));
110+
wireMockRule.verify(1, putRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/pods/foo")));
116111
assertNotNull(unlabelledPod);
117112
}
118113

@@ -178,24 +173,20 @@ public void testKubectlDeleteLabelClusterResourceShouldWork() throws KubectlExce
178173
.willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"foo\"}}")));
179174
wireMockRule.stubFor(
180175
put(urlPathEqualTo("/api/v1/nodes/foo"))
176+
.withRequestBody(
177+
matchingJsonPath(
178+
"$.metadata.labels", equalToJson("{ \"k1\": \"null\" }")))
181179
.willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"foo\"}}")));
182180

183-
Kubectl.label(V1Node.class)
184-
.apiClient(apiClient)
185-
.skipDiscovery()
186-
.name("foo")
187-
.addLabel("k1", "v1")
188-
.execute();
189-
190181
V1Node unlabelledNode =
191182
Kubectl.label(V1Node.class)
192183
.apiClient(apiClient)
193184
.skipDiscovery()
194185
.name("foo")
195186
.deleteLabel("k1")
196187
.execute();
197-
wireMockRule.verify(2, getRequestedFor(urlPathEqualTo("/api/v1/nodes/foo")));
198-
wireMockRule.verify(2, putRequestedFor(urlPathEqualTo("/api/v1/nodes/foo")));
188+
wireMockRule.verify(1, getRequestedFor(urlPathEqualTo("/api/v1/nodes/foo")));
189+
wireMockRule.verify(1, putRequestedFor(urlPathEqualTo("/api/v1/nodes/foo")));
199190
assertNotNull(unlabelledNode);
200191
}
201192

0 commit comments

Comments
 (0)