Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests to common module against mock kube #32

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading