Skip to content

Commit 6990dc3

Browse files
authored
Merge pull request kubernetes-client#1560 from yue9944882/formatting-groovy
Spotless: groovy formatting
2 parents 8dc8659 + 658cd14 commit 6990dc3

8 files changed

Lines changed: 250 additions & 219 deletions

File tree

e2e/src/test/groovy/io/kubernetes/client/e2e/basic/CoreV1ApiTest.groovy

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13-
1413
package io.kubernetes.client.e2e.basic
1514

1615
import io.kubernetes.client.openapi.Configuration
@@ -22,20 +21,19 @@ import io.kubernetes.client.util.ClientBuilder
2221
import spock.lang.Specification
2322

2423
class CoreV1ApiTest extends Specification {
25-
def "Create Namespace then Delete should work"() {
26-
given:
27-
def apiClient = ClientBuilder.defaultClient()
28-
def corev1api = new CoreV1Api(apiClient)
29-
Configuration.setDefaultApiClient(apiClient)
30-
def namespaceFoo = new V1Namespace().metadata(new V1ObjectMeta().name("e2e-basic"))
31-
when:
32-
V1Namespace created = corev1api.createNamespace(namespaceFoo, null, null, null)
33-
then:
34-
created != null
35-
when:
36-
V1Status deleted = corev1api.deleteNamespace("e2e-basic", null, null, null, null, null, null)
37-
then:
38-
deleted != null
39-
}
40-
24+
def "Create Namespace then Delete should work"() {
25+
given:
26+
def apiClient = ClientBuilder.defaultClient()
27+
def corev1api = new CoreV1Api(apiClient)
28+
Configuration.setDefaultApiClient(apiClient)
29+
def namespaceFoo = new V1Namespace().metadata(new V1ObjectMeta().name("e2e-basic"))
30+
when:
31+
V1Namespace created = corev1api.createNamespace(namespaceFoo, null, null, null)
32+
then:
33+
created != null
34+
when:
35+
V1Status deleted = corev1api.deleteNamespace("e2e-basic", null, null, null, null, null, null)
36+
then:
37+
deleted != null
38+
}
4139
}
Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
113
package io.kubernetes.client.e2e.csr
214

15+
import java.security.KeyPairGenerator
16+
import java.security.SecureRandom
17+
318
import io.kubernetes.client.openapi.ApiClient
419
import io.kubernetes.client.openapi.models.V1CertificateSigningRequest
520
import io.kubernetes.client.util.CSRUtils
@@ -8,47 +23,44 @@ import io.kubernetes.client.util.version.Version
823
import spock.lang.Specification
924
import spock.util.concurrent.PollingConditions
1025

11-
import java.security.KeyPairGenerator
12-
import java.security.SecureRandom
13-
1426
class CSRTest extends Specification {
15-
def "Build client instance via CSR should work"() {
16-
// initialize test environment
17-
given:
18-
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA")
19-
keyGen.initialize(2048, new SecureRandom())
20-
ApiClient bootstrapApiClient = ClientBuilder.defaultClient()
21-
22-
// generating key-pair
23-
when:
24-
def keyPair = keyGen.generateKeyPair()
25-
then:
26-
keyPair != null
27-
28-
// sign new CSR
29-
when:
30-
def csrBytes = CSRUtils.sign(keyPair, "foo")
31-
then:
32-
csrBytes != null
33-
34-
// creates CSR object against cluster
35-
when:
36-
def newCsr = CSRUtils.newV1CertificateSigningRequest("foo", csrBytes)
37-
def created = CSRUtils.createIfAbsent(bootstrapApiClient, newCsr)
38-
then:
39-
created
40-
41-
// reload certificates from CSR
42-
when:
43-
CSRUtils.approve(bootstrapApiClient, "foo")
44-
def signedApiClient = ClientBuilder.fromCertificateSigningRequest(bootstrapApiClient, keyPair.getPrivate(), newCsr)
45-
then:
46-
signedApiClient != null
47-
48-
// use the new client to get "/version"
49-
when:
50-
def v = new Version(signedApiClient).getVersion()
51-
then:
52-
v != null
53-
}
27+
def "Build client instance via CSR should work"() {
28+
// initialize test environment
29+
given:
30+
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA")
31+
keyGen.initialize(2048, new SecureRandom())
32+
ApiClient bootstrapApiClient = ClientBuilder.defaultClient()
33+
34+
// generating key-pair
35+
when:
36+
def keyPair = keyGen.generateKeyPair()
37+
then:
38+
keyPair != null
39+
40+
// sign new CSR
41+
when:
42+
def csrBytes = CSRUtils.sign(keyPair, "foo")
43+
then:
44+
csrBytes != null
45+
46+
// creates CSR object against cluster
47+
when:
48+
def newCsr = CSRUtils.newV1CertificateSigningRequest("foo", csrBytes)
49+
def created = CSRUtils.createIfAbsent(bootstrapApiClient, newCsr)
50+
then:
51+
created
52+
53+
// reload certificates from CSR
54+
when:
55+
CSRUtils.approve(bootstrapApiClient, "foo")
56+
def signedApiClient = ClientBuilder.fromCertificateSigningRequest(bootstrapApiClient, keyPair.getPrivate(), newCsr)
57+
then:
58+
signedApiClient != null
59+
60+
// use the new client to get "/version"
61+
when:
62+
def v = new Version(signedApiClient).getVersion()
63+
then:
64+
v != null
65+
}
5466
}
Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/*
2+
Copyright 2021 The Kubernetes Authors.
3+
Licensed under the Apache License, Version 2.0 (the "License");
4+
you may not use this file except in compliance with the License.
5+
You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software
8+
distributed under the License is distributed on an "AS IS" BASIS,
9+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
113
package io.kubernetes.client.e2e.dynamic
214

315

@@ -9,18 +21,18 @@ import io.kubernetes.client.util.generic.dynamic.Dynamics
921
import spock.lang.Specification
1022

1123
class DynamicApiTest extends Specification {
12-
def "Create Namespace then Delete should work"() {
13-
given:
14-
def apiClient = ClientBuilder.defaultClient()
15-
def dynamicApi = new DynamicKubernetesApi("", "v1", "namespaces", apiClient)
16-
def namespaceFoo = new V1Namespace().metadata(new V1ObjectMeta().name("e2e-dynamic"))
17-
when:
18-
def createdNamespace = dynamicApi.create(Dynamics.newFromJson(apiClient.getJSON().serialize(namespaceFoo)))
19-
then:
20-
createdNamespace != null
21-
when:
22-
def deleted = dynamicApi.delete("e2e-dynamic").throwsApiException().getObject()
23-
then:
24-
deleted != null
25-
}
24+
def "Create Namespace then Delete should work"() {
25+
given:
26+
def apiClient = ClientBuilder.defaultClient()
27+
def dynamicApi = new DynamicKubernetesApi("", "v1", "namespaces", apiClient)
28+
def namespaceFoo = new V1Namespace().metadata(new V1ObjectMeta().name("e2e-dynamic"))
29+
when:
30+
def createdNamespace = dynamicApi.create(Dynamics.newFromJson(apiClient.getJSON().serialize(namespaceFoo)))
31+
then:
32+
createdNamespace != null
33+
when:
34+
def deleted = dynamicApi.delete("e2e-dynamic").throwsApiException().getObject()
35+
then:
36+
deleted != null
37+
}
2638
}

e2e/src/test/groovy/io/kubernetes/client/e2e/informer/NamespaceInformerTest.groovy

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,27 @@ class NamespaceInformerTest extends Specification {
2525

2626
def "list-watching namespaces should work"() {
2727
given:
28-
def conditions = new PollingConditions()
29-
def apiClient = ClientBuilder.defaultClient()
30-
def api = new GenericKubernetesApi(
31-
V1Namespace.class,
32-
V1NamespaceList.class,
33-
"",
34-
"v1",
35-
"namespaces",
36-
apiClient)
37-
def informerFactory = new SharedInformerFactory()
38-
def nsInformer = informerFactory.sharedIndexInformerFor(
39-
api,
40-
V1Namespace.class,
41-
0)
42-
def nsLister = new Lister(nsInformer.getIndexer())
28+
def conditions = new PollingConditions()
29+
def apiClient = ClientBuilder.defaultClient()
30+
def api = new GenericKubernetesApi(
31+
V1Namespace.class,
32+
V1NamespaceList.class,
33+
"",
34+
"v1",
35+
"namespaces",
36+
apiClient)
37+
def informerFactory = new SharedInformerFactory()
38+
def nsInformer = informerFactory.sharedIndexInformerFor(
39+
api,
40+
V1Namespace.class,
41+
0)
42+
def nsLister = new Lister(nsInformer.getIndexer())
4343
when:
44-
informerFactory.startAllRegisteredInformers()
44+
informerFactory.startAllRegisteredInformers()
4545
then:
46-
conditions.eventually {
47-
nsInformer.hasSynced()
48-
nsLister.list().size() > 0
49-
}
46+
conditions.eventually {
47+
nsInformer.hasSynced()
48+
nsLister.list().size() > 0
49+
}
5050
}
51-
5251
}

e2e/src/test/groovy/io/kubernetes/client/e2e/kubectl/KubectlDrainTest.groovy

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1010
See the License for the specific language governing permissions and
1111
limitations under the License.
1212
*/
13-
1413
package io.kubernetes.client.e2e.kubectl
1514

1615
import io.kubernetes.client.extended.kubectl.Kubectl
@@ -28,36 +27,35 @@ import spock.lang.Specification
2827
class KubectlDrainTest extends Specification {
2928
def "Kubectl drain should work"() {
3029
given:
31-
def apiClient = ClientBuilder.defaultClient()
32-
Configuration.setDefaultApiClient(apiClient)
33-
def testNode = new V1Node()
34-
.metadata(new V1ObjectMeta().name("foo"))
35-
def testPod = new V1Pod()
36-
.metadata(new V1ObjectMeta()
37-
.namespace("default")
38-
.name("bar"))
39-
.spec(new V1PodSpec()
40-
.nodeName("foo")
41-
.containers(Arrays.asList(
42-
new V1Container().name("c1").image("nginx")
43-
)))
30+
def apiClient = ClientBuilder.defaultClient()
31+
Configuration.setDefaultApiClient(apiClient)
32+
def testNode = new V1Node()
33+
.metadata(new V1ObjectMeta().name("foo"))
34+
def testPod = new V1Pod()
35+
.metadata(new V1ObjectMeta()
36+
.namespace("default")
37+
.name("bar"))
38+
.spec(new V1PodSpec()
39+
.nodeName("foo")
40+
.containers(Arrays.asList(
41+
new V1Container().name("c1").image("nginx")
42+
)))
4443
when:
45-
V1Node createdNode = Kubectl.create(V1Node.class).resource(testNode).execute()
46-
V1Pod createdPod = Kubectl.create(V1Pod.class).resource(testPod).execute()
44+
V1Node createdNode = Kubectl.create(V1Node.class).resource(testNode).execute()
45+
V1Pod createdPod = Kubectl.create(V1Pod.class).resource(testPod).execute()
4746
then:
48-
createdNode != null
49-
createdPod != null
47+
createdNode != null
48+
createdPod != null
5049
when:
51-
V1Node drainedNode = Kubectl.drain().gracePeriod(0).name("foo").execute()
50+
V1Node drainedNode = Kubectl.drain().gracePeriod(0).name("foo").execute()
5251
then:
53-
drainedNode != null
52+
drainedNode != null
5453
when:
55-
Kubectl.get(V1Pod.class).namespace("default").name("bar").execute()
54+
Kubectl.get(V1Pod.class).namespace("default").name("bar").execute()
5655
then:
57-
def e = thrown KubectlException
58-
e.getCause().class == ApiException.class
56+
def e = thrown KubectlException
57+
e.getCause().class == ApiException.class
5958
cleanup:
60-
Kubectl.delete(V1Node.class).name("foo").execute()
59+
Kubectl.delete(V1Node.class).name("foo").execute()
6160
}
62-
6361
}

0 commit comments

Comments
 (0)