Skip to content

Commit

Permalink
Add tests to common module against mock kube (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
kornys authored Mar 15, 2024
1 parent b4573c9 commit 2c8974a
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 38 deletions.
23 changes: 23 additions & 0 deletions test-frame-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,28 @@
<artifactId>logback-classic</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.fabric8</groupId>
<artifactId>kubernetes-server-mock</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<test>io.skodjob.testframe.**</test>
<properties>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled = true
</configurationParameters>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public KubernetesClient getClient() {
return client;
}

/**
* Test method only
* Reconnect client with new config
* @param config kubernetes config
*/
void testReconnect(Config config) {
this.client = new KubernetesClientBuilder().withConfig(config).build();
}

/**
* Adapts the Kubernetes client to an OpenShift client.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Skodjob authors.
* License: Apache License 2.0 (see the file LICENSE or http://apache.org/licenses/LICENSE-2.0.html).
*/
package io.skodjob.testframe.clients;

import io.fabric8.kubernetes.api.model.NamespaceBuilder;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.server.mock.EnableKubernetesMockClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import io.skodjob.testframe.annotations.ResourceManager;
import io.skodjob.testframe.resources.KubeResourceManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

@EnableKubernetesMockClient(crud = true)
@ResourceManager
public class KubeResourceManagerTest {
private KubernetesClient kubernetesClient;
private KubernetesMockServer server;

@BeforeEach
void setupClient() {
KubeResourceManager.getKubeClient().testReconnect(kubernetesClient.getConfiguration());
}

@Test
void testCreateDeleteNamespace() {
KubeResourceManager.getInstance().createResourceWithWait(new NamespaceBuilder().withNewMetadata().withName("test").endMetadata().build());
assertNotNull(KubeResourceManager.getKubeClient().getClient().namespaces().withName("test").get());
}

@Test
void testDeleteAllResources() {
KubeResourceManager.getInstance().createResourceWithWait(new NamespaceBuilder().withNewMetadata().withName("test2").endMetadata().build());
assertNull(KubeResourceManager.getKubeClient().getClient().namespaces().withName("test").get());
assertNotNull(KubeResourceManager.getKubeClient().getClient().namespaces().withName("test2").get());
KubeResourceManager.getInstance().deleteResources();
assertNull(KubeResourceManager.getKubeClient().getClient().namespaces().withName("test2").get());
}
}
13 changes: 0 additions & 13 deletions test-frame-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
<configuration>
<test>io.skodjob.testframe.test.unit.**</test>
<properties>
<configurationParameters>
junit.jupiter.extensions.autodetection.enabled = true
</configurationParameters>
</properties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
Expand Down

This file was deleted.

0 comments on commit 2c8974a

Please sign in to comment.