Skip to content

Commit 0671ef8

Browse files
committed
refactored http returns to separate resource files
1 parent ba7d54c commit 0671ef8

File tree

5 files changed

+372
-9
lines changed

5 files changed

+372
-9
lines changed

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

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import io.kubernetes.client.extended.kubectl.exception.KubectlException;
2424
import io.kubernetes.client.openapi.ApiClient;
2525
import io.kubernetes.client.openapi.ApiException;
26-
import io.kubernetes.client.openapi.JSON;
2726
import io.kubernetes.client.openapi.apis.BatchV1Api;
2827
import io.kubernetes.client.openapi.models.*;
2928
import io.kubernetes.client.util.ClientBuilder;
@@ -33,7 +32,6 @@
3332
import java.nio.file.Files;
3433
import java.nio.file.Paths;
3534

36-
import io.kubernetes.client.util.generic.GenericKubernetesApi;
3735
import org.junit.Before;
3836
import org.junit.Rule;
3937
import org.junit.Test;
@@ -54,32 +52,62 @@ public class KubectlDeleteTest {
5452
.getPath())
5553
.toString();
5654

55+
56+
private static final String ADD_JOB =
57+
new File(
58+
KubectlDeleteTest.class
59+
.getClassLoader()
60+
.getResource("deleted-add-job.json")
61+
.getPath())
62+
.toString();
63+
private static final String GET_BATCH =
64+
new File(
65+
KubectlDeleteTest.class
66+
.getClassLoader()
67+
.getResource("deleted-get-batch.json")
68+
.getPath())
69+
.toString();
70+
private static final String DELETED_FIRST =
71+
new File(
72+
KubectlDeleteTest.class
73+
.getClassLoader()
74+
.getResource("deleted-first-time.json")
75+
.getPath())
76+
.toString();
77+
private static final String DELETED_SECOND =
78+
new File(
79+
KubectlDeleteTest.class
80+
.getClassLoader()
81+
.getResource("deleted-second-time.json")
82+
.getPath())
83+
.toString();
84+
5785
private static final String DISCOVERY_APIS =
5886
new File(KubectlDeleteTest.class.getClassLoader().getResource("discovery-apis.json").getPath())
5987
.toString();
6088

6189
@Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort());
6290

6391
@Before
64-
public void setup() throws IOException {
92+
public void setup() {
6593
apiClient = new ClientBuilder().setBasePath("http://localhost:" + wireMockRule.port()).build();
6694
}
6795

6896
@Test
69-
public void testKubectlDelete() throws KubectlException, IOException, ApiException, InterruptedException {
97+
public void testKubectlDelete() throws KubectlException, IOException, ApiException {
7098
wireMockRule.stubFor(
7199
post(urlPathEqualTo("/apis/batch/v1/namespaces/foo/jobs"))
72100
.willReturn(
73101
aResponse()
74102
.withStatus(201)
75-
.withBody("{\"kind\":\"Job\",\"apiVersion\":\"batch/v1\",\"metadata\":{\"name\":\"bar\",\"namespace\":\"foo\",\"uid\":\"7f64e06e-d6a6-4598-b375-7c8773f3b0e7\",\"resourceVersion\":\"46205\",\"generation\":1,\"creationTimestamp\":\"2023-11-23T15:38:18Z\",\"labels\":{\"batch.kubernetes.io/controller-uid\":\"7f64e06e-d6a6-4598-b375-7c8773f3b0e7\",\"batch.kubernetes.io/job-name\":\"bar\",\"controller-uid\":\"7f64e06e-d6a6-4598-b375-7c8773f3b0e7\",\"job-name\":\"bar\"},\"annotations\":{\"batch.kubernetes.io/job-tracking\":\"\"},\"managedFields\":[{\"manager\":\"Kubernetes Java Client\",\"operation\":\"Update\",\"apiVersion\":\"batch/v1\",\"time\":\"2023-11-23T15:38:18Z\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:spec\":{\"f:backoffLimit\":{},\"f:completionMode\":{},\"f:completions\":{},\"f:parallelism\":{},\"f:suspend\":{},\"f:template\":{\"f:spec\":{\"f:containers\":{\"k:{\\\"name\\\":\\\"bar2\\\"}\":{\".\":{},\"f:command\":{},\"f:image\":{},\"f:imagePullPolicy\":{},\"f:name\":{},\"f:resources\":{},\"f:terminationMessagePath\":{},\"f:terminationMessagePolicy\":{}}},\"f:dnsPolicy\":{},\"f:restartPolicy\":{},\"f:schedulerName\":{},\"f:securityContext\":{},\"f:terminationGracePeriodSeconds\":{}}}}}}]},\"spec\":{\"parallelism\":1,\"completions\":1,\"backoffLimit\":6,\"selector\":{\"matchLabels\":{\"batch.kubernetes.io/controller-uid\":\"7f64e06e-d6a6-4598-b375-7c8773f3b0e7\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"batch.kubernetes.io/controller-uid\":\"7f64e06e-d6a6-4598-b375-7c8773f3b0e7\",\"batch.kubernetes.io/job-name\":\"bar\",\"controller-uid\":\"7f64e06e-d6a6-4598-b375-7c8773f3b0e7\",\"job-name\":\"bar\"}},\"spec\":{\"containers\":[{\"name\":\"bar2\",\"image\":\"busybox\",\"command\":[\"sh\",\"-c\",\"echo Hello World!\"],\"resources\":{},\"terminationMessagePath\":\"/dev/termination-log\",\"terminationMessagePolicy\":\"File\",\"imagePullPolicy\":\"Always\"}],\"restartPolicy\":\"Never\",\"terminationGracePeriodSeconds\":30,\"dnsPolicy\":\"ClusterFirst\",\"securityContext\":{},\"schedulerName\":\"default-scheduler\"}},\"completionMode\":\"NonIndexed\",\"suspend\":false},\"status\":{}}")));
103+
.withBody(new String(Files.readAllBytes(Paths.get(ADD_JOB))))));
76104
wireMockRule.stubFor(
77105
delete(urlPathEqualTo("/apis/batch%2Fv1/batch%2Fv1/namespaces/foo/jobs/bar"))
78106
.inScenario("JobDeletionScenario")
79107
.whenScenarioStateIs(Scenario.STARTED)
80108
.willReturn(aResponse()
81-
.withStatus(200)
82-
.withBody("{\"kind\":\"Job\",\"apiVersion\":\"batch/v1\",\"metadata\":{\"name\":\"bar\",\"namespace\":\"foo\",\"uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"resourceVersion\":\"82015\",\"generation\":2,\"creationTimestamp\":\"2023-11-24T06:00:49Z\",\"deletionTimestamp\":\"2023-11-24T06:07:44Z\",\"deletionGracePeriodSeconds\":0,\"labels\":{\"batch.kubernetes.io/controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"batch.kubernetes.io/job-name\":\"bar\",\"controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"job-name\":\"bar\"},\"annotations\":{\"batch.kubernetes.io/job-tracking\":\"\"},\"finalizers\":[\"orphan\"],\"managedFields\":[{\"manager\":\"Kubernetes Java Client\",\"operation\":\"Update\",\"apiVersion\":\"batch/v1\",\"time\":\"2023-11-24T06:00:49Z\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:spec\":{\"f:backoffLimit\":{},\"f:completionMode\":{},\"f:completions\":{},\"f:parallelism\":{},\"f:suspend\":{},\"f:template\":{\"f:spec\":{\"f:containers\":{\"k:{\\\"name\\\":\\\"bar2\\\"}\":{\".\":{},\"f:command\":{},\"f:image\":{},\"f:imagePullPolicy\":{},\"f:name\":{},\"f:resources\":{},\"f:terminationMessagePath\":{},\"f:terminationMessagePolicy\":{}}},\"f:dnsPolicy\":{},\"f:restartPolicy\":{},\"f:schedulerName\":{},\"f:securityContext\":{},\"f:terminationGracePeriodSeconds\":{}}}}}},{\"manager\":\"kube-controller-manager\",\"operation\":\"Update\",\"apiVersion\":\"batch/v1\",\"time\":\"2023-11-24T06:00:53Z\",\"fieldsType\":\"FieldsV1\",\"fieldsV1\":{\"f:status\":{\"f:completionTime\":{},\"f:conditions\":{},\"f:ready\":{},\"f:startTime\":{},\"f:succeeded\":{},\"f:uncountedTerminatedPods\":{}}},\"subresource\":\"status\"}]},\"spec\":{\"parallelism\":1,\"completions\":1,\"backoffLimit\":6,\"selector\":{\"matchLabels\":{\"batch.kubernetes.io/controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\"}},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"batch.kubernetes.io/controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"batch.kubernetes.io/job-name\":\"bar\",\"controller-uid\":\"b862e993-3828-4108-a38f-c19a602d9af6\",\"job-name\":\"bar\"}},\"spec\":{\"containers\":[{\"name\":\"bar2\",\"image\":\"busybox\",\"command\":[\"sh\",\"-c\",\"echo Hello World!\"],\"resources\":{},\"terminationMessagePath\":\"/dev/termination-log\",\"terminationMessagePolicy\":\"File\",\"imagePullPolicy\":\"Always\"}],\"restartPolicy\":\"Never\",\"terminationGracePeriodSeconds\":30,\"dnsPolicy\":\"ClusterFirst\",\"securityContext\":{},\"schedulerName\":\"default-scheduler\"}},\"completionMode\":\"NonIndexed\",\"suspend\":false},\"status\":{\"conditions\":[{\"type\":\"Complete\",\"status\":\"True\",\"lastProbeTime\":\"2023-11-24T06:00:53Z\",\"lastTransitionTime\":\"2023-11-24T06:00:53Z\"}],\"startTime\":\"2023-11-24T06:00:49Z\",\"completionTime\":\"2023-11-24T06:00:53Z\",\"succeeded\":1,\"uncountedTerminatedPods\":{},\"ready\":0}}\n")
109+
.withStatus(200)
110+
.withBody(new String(Files.readAllBytes(Paths.get(DELETED_FIRST))))
83111
)
84112
.willSetStateTo("SecondCall")
85113
);
@@ -90,7 +118,7 @@ public void testKubectlDelete() throws KubectlException, IOException, ApiExcepti
90118
.whenScenarioStateIs("SecondCall")
91119
.willReturn(aResponse()
92120
.withStatus(404)
93-
.withBody("{\"kind\":\"Status\",\"apiVersion\":\"v1\",\"metadata\":{},\"status\":\"Failure\",\"message\":\"jobs.batch \\\"bar\\\" not found\",\"reason\":\"NotFound\",\"details\":{\"name\":\"bar\",\"group\":\"batch\",\"kind\":\"jobs\"},\"code\":404}")
121+
.withBody(new String(Files.readAllBytes(Paths.get(DELETED_SECOND))))
94122
)
95123
);
96124

@@ -117,7 +145,7 @@ public void testKubectlDelete() throws KubectlException, IOException, ApiExcepti
117145
.willReturn(
118146
aResponse()
119147
.withStatus(200)
120-
.withBody("{\"kind\":\"APIResourceList\",\"apiVersion\":\"v1\",\"groupVersion\":\"batch/v1\",\"resources\":[{\"name\":\"cronjobs\",\"singularName\":\"cronjob\",\"namespaced\":true,\"kind\":\"CronJob\",\"verbs\":[\"create\",\"delete\",\"deletecollection\",\"get\",\"list\",\"patch\",\"update\",\"watch\"],\"shortNames\":[\"cj\"],\"categories\":[\"all\"],\"storageVersionHash\":\"sd5LIXh4Fjs=\"},{\"name\":\"cronjobs/status\",\"singularName\":\"\",\"namespaced\":true,\"kind\":\"CronJob\",\"verbs\":[\"get\",\"patch\",\"update\"]},{\"name\":\"jobs\",\"singularName\":\"job\",\"namespaced\":true,\"kind\":\"Job\",\"verbs\":[\"create\",\"delete\",\"deletecollection\",\"get\",\"list\",\"patch\",\"update\",\"watch\"],\"categories\":[\"all\"],\"storageVersionHash\":\"mudhfqk/qZY=\"},{\"name\":\"jobs/status\",\"singularName\":\"\",\"namespaced\":true,\"kind\":\"Job\",\"verbs\":[\"get\",\"patch\",\"update\"]}]}\n")));
148+
.withBody(new String(Files.readAllBytes(Paths.get(GET_BATCH))))));
121149

122150
V1JobSpec v1JobSpec = new V1JobSpec()
123151
.template(new V1PodTemplateSpec()
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"kind": "Job",
3+
"apiVersion": "batch/v1",
4+
"metadata": {
5+
"name": "bar",
6+
"namespace": "foo",
7+
"uid": "7f64e06e-d6a6-4598-b375-7c8773f3b0e7",
8+
"resourceVersion": "46205",
9+
"generation": 1,
10+
"creationTimestamp": "2023-11-23T15:38:18Z",
11+
"labels": {
12+
"batch.kubernetes.io/controller-uid": "7f64e06e-d6a6-4598-b375-7c8773f3b0e7",
13+
"batch.kubernetes.io/job-name": "bar",
14+
"controller-uid": "7f64e06e-d6a6-4598-b375-7c8773f3b0e7",
15+
"job-name": "bar"
16+
},
17+
"annotations": {
18+
"batch.kubernetes.io/job-tracking": ""
19+
},
20+
"managedFields": [
21+
{
22+
"manager": "Kubernetes Java Client",
23+
"operation": "Update",
24+
"apiVersion": "batch/v1",
25+
"time": "2023-11-23T15:38:18Z",
26+
"fieldsType": "FieldsV1",
27+
"fieldsV1": {
28+
"f:spec": {
29+
"f:backoffLimit": {},
30+
"f:completionMode": {},
31+
"f:completions": {},
32+
"f:parallelism": {},
33+
"f:suspend": {},
34+
"f:template": {
35+
"f:spec": {
36+
"f:containers": {
37+
"k:{\"name\":\"bar2\"}": {
38+
".": {},
39+
"f:command": {},
40+
"f:image": {},
41+
"f:imagePullPolicy": {},
42+
"f:name": {},
43+
"f:resources": {},
44+
"f:terminationMessagePath": {},
45+
"f:terminationMessagePolicy": {}
46+
}
47+
},
48+
"f:dnsPolicy": {},
49+
"f:restartPolicy": {},
50+
"f:schedulerName": {},
51+
"f:securityContext": {},
52+
"f:terminationGracePeriodSeconds": {}
53+
}
54+
}
55+
}
56+
}
57+
}
58+
]
59+
},
60+
"spec": {
61+
"parallelism": 1,
62+
"completions": 1,
63+
"backoffLimit": 6,
64+
"selector": {
65+
"matchLabels": {
66+
"batch.kubernetes.io/controller-uid": "7f64e06e-d6a6-4598-b375-7c8773f3b0e7"
67+
}
68+
},
69+
"template": {
70+
"metadata": {
71+
"creationTimestamp": null,
72+
"labels": {
73+
"batch.kubernetes.io/controller-uid": "7f64e06e-d6a6-4598-b375-7c8773f3b0e7",
74+
"batch.kubernetes.io/job-name": "bar",
75+
"controller-uid": "7f64e06e-d6a6-4598-b375-7c8773f3b0e7",
76+
"job-name": "bar"
77+
}
78+
},
79+
"spec": {
80+
"containers": [
81+
{
82+
"name": "bar2",
83+
"image": "busybox",
84+
"command": [
85+
"sh",
86+
"-c",
87+
"echo Hello World!"
88+
],
89+
"resources": {},
90+
"terminationMessagePath": "/dev/termination-log",
91+
"terminationMessagePolicy": "File",
92+
"imagePullPolicy": "Always"
93+
}
94+
],
95+
"restartPolicy": "Never",
96+
"terminationGracePeriodSeconds": 30,
97+
"dnsPolicy": "ClusterFirst",
98+
"securityContext": {},
99+
"schedulerName": "default-scheduler"
100+
}
101+
},
102+
"completionMode": "NonIndexed",
103+
"suspend": false
104+
},
105+
"status": {}
106+
}
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
{
2+
"kind": "Job",
3+
"apiVersion": "batch/v1",
4+
"metadata": {
5+
"name": "bar",
6+
"namespace": "foo",
7+
"uid": "b862e993-3828-4108-a38f-c19a602d9af6",
8+
"resourceVersion": "82015",
9+
"generation": 2,
10+
"creationTimestamp": "2023-11-24T06:00:49Z",
11+
"deletionTimestamp": "2023-11-24T06:07:44Z",
12+
"deletionGracePeriodSeconds": 0,
13+
"labels": {
14+
"batch.kubernetes.io/controller-uid": "b862e993-3828-4108-a38f-c19a602d9af6",
15+
"batch.kubernetes.io/job-name": "bar",
16+
"controller-uid": "b862e993-3828-4108-a38f-c19a602d9af6",
17+
"job-name": "bar"
18+
},
19+
"annotations": {
20+
"batch.kubernetes.io/job-tracking": ""
21+
},
22+
"finalizers": [
23+
"orphan"
24+
],
25+
"managedFields": [
26+
{
27+
"manager": "Kubernetes Java Client",
28+
"operation": "Update",
29+
"apiVersion": "batch/v1",
30+
"time": "2023-11-24T06:00:49Z",
31+
"fieldsType": "FieldsV1",
32+
"fieldsV1": {
33+
"f:spec": {
34+
"f:backoffLimit": {},
35+
"f:completionMode": {},
36+
"f:completions": {},
37+
"f:parallelism": {},
38+
"f:suspend": {},
39+
"f:template": {
40+
"f:spec": {
41+
"f:containers": {
42+
"k:{\"name\":\"bar2\"}": {
43+
".": {},
44+
"f:command": {},
45+
"f:image": {},
46+
"f:imagePullPolicy": {},
47+
"f:name": {},
48+
"f:resources": {},
49+
"f:terminationMessagePath": {},
50+
"f:terminationMessagePolicy": {}
51+
}
52+
},
53+
"f:dnsPolicy": {},
54+
"f:restartPolicy": {},
55+
"f:schedulerName": {},
56+
"f:securityContext": {},
57+
"f:terminationGracePeriodSeconds": {}
58+
}
59+
}
60+
}
61+
}
62+
},
63+
{
64+
"manager": "kube-controller-manager",
65+
"operation": "Update",
66+
"apiVersion": "batch/v1",
67+
"time": "2023-11-24T06:00:53Z",
68+
"fieldsType": "FieldsV1",
69+
"fieldsV1": {
70+
"f:status": {
71+
"f:completionTime": {},
72+
"f:conditions": {},
73+
"f:ready": {},
74+
"f:startTime": {},
75+
"f:succeeded": {},
76+
"f:uncountedTerminatedPods": {}
77+
}
78+
},
79+
"subresource": "status"
80+
}
81+
]
82+
},
83+
"spec": {
84+
"parallelism": 1,
85+
"completions": 1,
86+
"backoffLimit": 6,
87+
"selector": {
88+
"matchLabels": {
89+
"batch.kubernetes.io/controller-uid": "b862e993-3828-4108-a38f-c19a602d9af6"
90+
}
91+
},
92+
"template": {
93+
"metadata": {
94+
"creationTimestamp": null,
95+
"labels": {
96+
"batch.kubernetes.io/controller-uid": "b862e993-3828-4108-a38f-c19a602d9af6",
97+
"batch.kubernetes.io/job-name": "bar",
98+
"controller-uid": "b862e993-3828-4108-a38f-c19a602d9af6",
99+
"job-name": "bar"
100+
}
101+
},
102+
"spec": {
103+
"containers": [
104+
{
105+
"name": "bar2",
106+
"image": "busybox",
107+
"command": [
108+
"sh",
109+
"-c",
110+
"echo Hello World!"
111+
],
112+
"resources": {},
113+
"terminationMessagePath": "/dev/termination-log",
114+
"terminationMessagePolicy": "File",
115+
"imagePullPolicy": "Always"
116+
}
117+
],
118+
"restartPolicy": "Never",
119+
"terminationGracePeriodSeconds": 30,
120+
"dnsPolicy": "ClusterFirst",
121+
"securityContext": {},
122+
"schedulerName": "default-scheduler"
123+
}
124+
},
125+
"completionMode": "NonIndexed",
126+
"suspend": false
127+
},
128+
"status": {
129+
"conditions": [
130+
{
131+
"type": "Complete",
132+
"status": "True",
133+
"lastProbeTime": "2023-11-24T06:00:53Z",
134+
"lastTransitionTime": "2023-11-24T06:00:53Z"
135+
}
136+
],
137+
"startTime": "2023-11-24T06:00:49Z",
138+
"completionTime": "2023-11-24T06:00:53Z",
139+
"succeeded": 1,
140+
"uncountedTerminatedPods": {},
141+
"ready": 0
142+
}
143+
}

0 commit comments

Comments
 (0)