Skip to content

Commit 6640463

Browse files
committed
Refactor Integration tests to not depend on Arquillian
1 parent 2e901af commit 6640463

File tree

5 files changed

+800
-790
lines changed

5 files changed

+800
-790
lines changed

pom.xml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -289,29 +289,6 @@
289289
<version>2.11.2</version>
290290
</dependency>
291291

292-
293-
<!-- Deps for tests -->
294-
<dependency>
295-
<groupId>org.arquillian.cube</groupId>
296-
<artifactId>arquillian-cube-bom</artifactId>
297-
<version>${version.arquillian_cube}</version>
298-
<scope>import</scope>
299-
<type>pom</type>
300-
</dependency>
301-
<dependency>
302-
<groupId>org.arquillian.cube</groupId>
303-
<artifactId>arquillian-cube-kubernetes-starter</artifactId>
304-
<version>${version.arquillian_cube}</version>
305-
<scope>test</scope>
306-
</dependency>
307-
<dependency>
308-
<groupId>org.arquillian.cube</groupId>
309-
<artifactId>arquillian-cube-requirement</artifactId>
310-
<version>${version.arquillian_cube}</version>
311-
<scope>test</scope>
312-
</dependency>
313-
314-
315292
<!-- Recursive dependencies which are upgraded for security -->
316293
<dependency>
317294
<groupId>commons-collections</groupId>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/**
2+
* ContainerProxy
3+
*
4+
* Copyright (C) 2016-2020 Open Analytics
5+
*
6+
* ===========================================================================
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the Apache License as published by
10+
* The Apache Software Foundation, either version 2 of the License, or
11+
* (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* Apache License for more details.
17+
*
18+
* You should have received a copy of the Apache License
19+
* along with this program. If not, see <http://www.apache.org/licenses/>
20+
*/
21+
package eu.openanalytics.containerproxy.test.helpers;
22+
23+
import io.fabric8.kubernetes.api.model.Namespace;
24+
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
25+
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
26+
import io.fabric8.kubernetes.client.NamespacedKubernetesClient;
27+
28+
import java.util.Arrays;
29+
import java.util.List;
30+
31+
public abstract class KubernetesTestBase {
32+
33+
public static interface TestBody {
34+
public void run(NamespacedKubernetesClient client, String namespace, String overriddenNamespace) throws InterruptedException;
35+
}
36+
37+
public static final String namespace = "itest";
38+
public static final String overriddenNamespace = "itest-overridden";
39+
private final List<String> managedNamespaces = Arrays.asList(namespace, overriddenNamespace);
40+
41+
static protected final DefaultKubernetesClient client = new DefaultKubernetesClient();
42+
43+
protected void setup(TestBody test) {
44+
Runtime.getRuntime().addShutdownHook(new Thread(this::deleteNamespaces));
45+
46+
deleteNamespaces();
47+
createNamespaces();
48+
49+
try {
50+
Thread.sleep(1000); // wait for namespaces and tokens to become ready
51+
52+
NamespacedKubernetesClient namespacedKubernetesClient = client.inNamespace(namespace);
53+
54+
test.run(namespacedKubernetesClient, namespace, overriddenNamespace);
55+
} catch (InterruptedException e) {
56+
} finally {
57+
deleteNamespaces();
58+
}
59+
}
60+
61+
private void deleteNamespaces() {
62+
try {
63+
for (String namespace : managedNamespaces) {
64+
Namespace ns = client.namespaces().withName(namespace).get();
65+
if (ns == null) {
66+
continue;
67+
}
68+
69+
client.namespaces().delete(ns);
70+
71+
while (client.namespaces().withName(namespace).get() != null) {
72+
Thread.sleep(1000);
73+
}
74+
}
75+
} catch (InterruptedException e) {
76+
}
77+
}
78+
79+
private void createNamespaces() {
80+
for (String namespace : managedNamespaces) {
81+
client.namespaces().create(new NamespaceBuilder()
82+
.withNewMetadata()
83+
.withName(namespace)
84+
.endMetadata()
85+
.build());
86+
}
87+
}
88+
89+
}

src/test/java/eu/openanalytics/containerproxy/test/proxy/PropertyOverrideContextInitializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ public class PropertyOverrideContextInitializer
3030
@Override
3131
public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
3232
TestPropertySourceUtils.addInlinedPropertiesToEnvironment(configurableApplicationContext,
33-
"proxy.kubernetes.namespace=" + TestIntegrationOnKube.session.getNamespace());
33+
"proxy.kubernetes.namespace=" + TestIntegrationOnKube.namespace);
3434
}
3535
}

0 commit comments

Comments
 (0)