Skip to content

Commit b8fa02b

Browse files
authored
Add tests for create callbacks (#57)
Signed-off-by: David Kornel <[email protected]>
1 parent 95c54ec commit b8fa02b

File tree

5 files changed

+30
-5
lines changed

5 files changed

+30
-5
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@
9595
<artifactId>test-frame-common</artifactId>
9696
<version>${project.version}</version>
9797
</dependency>
98+
<dependency>
99+
<groupId>io.skodjob</groupId>
100+
<artifactId>test-frame-kubernetes</artifactId>
101+
<version>${project.version}</version>
102+
</dependency>
98103
<dependency>
99104
<groupId>io.fabric8</groupId>
100105
<artifactId>kubernetes-client-api</artifactId>

test-frame-test/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
<groupId>io.skodjob</groupId>
3131
<artifactId>test-frame-common</artifactId>
3232
</dependency>
33+
<dependency>
34+
<groupId>io.skodjob</groupId>
35+
<artifactId>test-frame-kubernetes</artifactId>
36+
</dependency>
3337
<dependency>
3438
<groupId>io.fabric8</groupId>
3539
<artifactId>openshift-client</artifactId>
@@ -101,7 +105,7 @@
101105
</executions>
102106
<configuration>
103107
<skipITs>${it.skip}</skipITs>
104-
<forkCount>0</forkCount>
108+
<forkCount>1</forkCount>
105109
<includes>
106110
<include>io.skodjob.testframe.test.integration.**</include>
107111
</includes>
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
package io.skodjob.testframe.test.integration;
22

33
import io.skodjob.testframe.annotations.ResourceManager;
4+
import io.skodjob.testframe.resources.KubeResourceManager;
5+
import io.skodjob.testframe.resources.NamespaceResource;
6+
import io.skodjob.testframe.resources.ServiceAccountResource;
7+
import io.skodjob.testframe.utils.KubeUtils;
48

5-
@ResourceManager()
9+
@ResourceManager
610
public class AbstractIT {
11+
static {
12+
KubeResourceManager.getInstance().setResourceTypes(
13+
new NamespaceResource(),
14+
new ServiceAccountResource()
15+
);
16+
KubeResourceManager.getInstance().addCreateCallback(r -> {
17+
if (r.getKind().equals("Namespace")) {
18+
KubeUtils.labelNamespace(r.getMetadata().getName(), "test-label", "true");
19+
}
20+
});
21+
}
22+
723
protected String nsName = "test";
824
}

test-frame-test/src/test/java/io/skodjob/testframe/test/integration/KubeClientIT.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package io.skodjob.testframe.test.integration;
66

77
import io.fabric8.kubernetes.api.model.HasMetadata;
8-
import io.skodjob.testframe.annotations.ResourceManager;
98
import io.skodjob.testframe.annotations.TestVisualSeparator;
109
import io.skodjob.testframe.resources.KubeResourceManager;
1110
import org.junit.jupiter.api.Test;
@@ -16,10 +15,9 @@
1615

1716
import static org.junit.jupiter.api.Assertions.assertNotNull;
1817

19-
@ResourceManager
2018
@TestVisualSeparator
2119
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
22-
public class KubeClientIT {
20+
public class KubeClientIT extends AbstractIT {
2321

2422
@Test
2523
void testCreateResourcesFromYaml() throws IOException {

test-frame-test/src/test/java/io/skodjob/testframe/test/integration/KubeResourceManagerCleanerIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ void createResource() {
4646
Namespace ns = new NamespaceBuilder().withNewMetadata().withName("test3").endMetadata().build();
4747
KubeResourceManager.getInstance().createResourceWithWait(ns);
4848
KubeResourceManager.getInstance().createOrUpdateResourceWithWait(ns);
49+
assertNotNull(KubeResourceManager.getKubeClient().getClient().namespaces().withName("test3").get()
50+
.getMetadata().getLabels().get("test-label"));
4951
}
5052

5153
@Test

0 commit comments

Comments
 (0)