Skip to content

Commit

Permalink
Added @WithKubernetesTestServer meta-annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
FroMage committed Feb 9, 2021
1 parent 62a37f3 commit 583b057
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,14 @@
import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.common.ResourceArg;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.QuarkusTestProfile;
import io.quarkus.test.junit.TestProfile;
import io.quarkus.test.kubernetes.client.KubernetesServerTestResource;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;

@TestProfile(KubernetesTestServerTest.MyProfile.class)
@QuarkusTestResource(value = KubernetesServerTestResource.class, initArgs = {
@ResourceArg(name = KubernetesServerTestResource.HTTPS, value = "false"),
@ResourceArg(name = KubernetesServerTestResource.CRUD, value = "false"),
@ResourceArg(name = KubernetesServerTestResource.PORT, value = "10001"),
})
@WithKubernetesTestServer(https = false, crud = true, port = 10001)
@QuarkusTest
public class KubernetesTestServerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,23 @@
import java.lang.annotation.Annotation;
import java.net.InetAddress;
import java.util.Collections;
import java.util.Map;

import io.fabric8.kubernetes.client.GenericKubernetesClient;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.common.QuarkusTestResourceConfigurableLifecycleManager;

public class KubernetesServerTestResource extends AbstractKubernetesTestResource<KubernetesServer> {

/**
* Configure HTTPS usage, defaults to false
*/
public final static String HTTPS = "https";
/**
* Configure CRUD usage, defaults to true
*/
public final static String CRUD = "crud";
/**
* Configure the port to use, defaults to 0, for the first available port
*/
public final static String PORT = "port";
public class KubernetesServerTestResource extends AbstractKubernetesTestResource<KubernetesServer>
implements QuarkusTestResourceConfigurableLifecycleManager<WithKubernetesTestServer> {

private boolean https = false;
private boolean crud = true;
private int port = 0;

@Override
public void init(Map<String, String> initArgs) {
String val = initArgs.get(HTTPS);
if (val != null) {
this.https = Boolean.parseBoolean(val);
}
val = initArgs.get(CRUD);
if (val != null) {
this.crud = Boolean.parseBoolean(val);
}
val = initArgs.get(PORT);
if (val != null) {
this.port = Integer.parseInt(val);
}
public void init(WithKubernetesTestServer annotation) {
this.https = annotation.https();
this.crud = annotation.crud();
this.port = annotation.port();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.quarkus.test.kubernetes.client;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.quarkus.test.common.QuarkusTestResource;

/**
* Use on your test resource to get a mock {@link KubernetesServer} spawn up, and injectable with {@link KubernetesTestServer}.
* This annotation is only active when used on a test class, and only for this test class.
*/
@QuarkusTestResource(value = KubernetesServerTestResource.class, restrictToAnnotatedTest = true)
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface WithKubernetesTestServer {

/**
* Start it with HTTPS
*/
boolean https() default false;

/**
* Start it in CRUD mode
*/
boolean crud() default true;

/**
* Port to use, defaults to any available port
*/
int port() default 0;

}

0 comments on commit 583b057

Please sign in to comment.