Skip to content

Commit 2ddce2f

Browse files
committed
Add validation that the request body is as expected.
1 parent 6011c4a commit 2ddce2f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
package io.kubernetes.client.extended.kubectl;
1414

1515
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
16+
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson;
1617
import static com.github.tomakehurst.wiremock.client.WireMock.get;
1718
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor;
19+
import static com.github.tomakehurst.wiremock.client.WireMock.matchingJsonPath;
1820
import static com.github.tomakehurst.wiremock.client.WireMock.put;
1921
import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor;
2022
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
@@ -56,6 +58,9 @@ public void testKubectlLabelNamespacedResourceShouldWork() throws KubectlExcepti
5658
.withBody("{\"metadata\":{\"name\":\"foo\",\"namespace\":\"default\"}}")));
5759
wireMockRule.stubFor(
5860
put(urlPathEqualTo("/api/v1/namespaces/default/pods/foo"))
61+
.withRequestBody(
62+
matchingJsonPath(
63+
"$.metadata.labels", equalToJson("{ \"k1\": \"v1\", \"k2\": \"v2\" }")))
5964
.willReturn(
6065
aResponse()
6166
.withStatus(200)
@@ -85,6 +90,9 @@ public void testKubectlLabelNamespacedResourceReceiveForbiddenShouldThrowExcepti
8590
.withBody("{\"metadata\":{\"name\":\"foo\",\"namespace\":\"default\"}}")));
8691
wireMockRule.stubFor(
8792
put(urlPathEqualTo("/api/v1/namespaces/default/pods/foo"))
93+
.withRequestBody(
94+
matchingJsonPath(
95+
"$.metadata.labels", equalToJson("{ \"k1\": \"v1\", \"k2\": \"v2\" }")))
8896
.willReturn(aResponse().withStatus(403).withBody("{\"metadata\":{}}")));
8997
assertThrows(
9098
KubectlException.class,
@@ -109,6 +117,9 @@ public void testKubectlLabelClusterResourceShouldWork() throws KubectlException
109117
.willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"foo\"}}")));
110118
wireMockRule.stubFor(
111119
put(urlPathEqualTo("/api/v1/nodes/foo"))
120+
.withRequestBody(
121+
matchingJsonPath(
122+
"$.metadata.labels", equalToJson("{ \"k1\": \"v1\", \"k2\": \"v2\" }")))
112123
.willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"foo\"}}")));
113124
V1Node labelledNode =
114125
Kubectl.label(V1Node.class)
@@ -131,6 +142,9 @@ public void testKubectlLabelClusterResourceReceiveForbiddenShouldThrowException(
131142
.willReturn(aResponse().withStatus(200).withBody("{\"metadata\":{\"name\":\"foo\"}}")));
132143
wireMockRule.stubFor(
133144
put(urlPathEqualTo("/api/v1/nodes/foo"))
145+
.withRequestBody(
146+
matchingJsonPath(
147+
"$.metadata.labels", equalToJson("{ \"k1\": \"v1\", \"k2\": \"v2\" }")))
134148
.willReturn(aResponse().withStatus(403).withBody("{\"metadata\":{\"name\":\"foo\"}}")));
135149
assertThrows(
136150
KubectlException.class,

0 commit comments

Comments
 (0)