-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18929 from manusa/feat/with-openshift-server-test
Introduce @WithOpenShiftTestServer annotation
- 3.17.6
- 3.17.5
- 3.17.4
- 3.17.3
- 3.17.2
- 3.17.1
- 3.17.0
- 3.17.0.CR1
- 3.16.4
- 3.16.3
- 3.16.2
- 3.16.1
- 3.16.0
- 3.16.0.CR1
- 3.15.2
- 3.15.1
- 3.15.0
- 3.15.0.CR1
- 3.14.4
- 3.14.3
- 3.14.2
- 3.14.1
- 3.14.0
- 3.14.0.CR1
- 3.13.3
- 3.13.2
- 3.13.1
- 3.13.0
- 3.13.0.CR1
- 3.12.3
- 3.12.2
- 3.12.1
- 3.12.0
- 3.12.0.CR1
- 3.11.3
- 3.11.2
- 3.11.1
- 3.11.0
- 3.11.0.CR1
- 3.10.2
- 3.10.1
- 3.10.0
- 3.10.0.CR1
- 3.9.5
- 3.9.4
- 3.9.3
- 3.9.2
- 3.9.1
- 3.9.0
- 3.9.0.CR2
- 3.9.0.CR1
- 3.8.6
- 3.8.5
- 3.8.4
- 3.8.3
- 3.8.2
- 3.8.1
- 3.8.0
- 3.8.0.CR1
- 3.7.4
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.7.0.CR1
- 3.6.9
- 3.6.8
- 3.6.7
- 3.6.6
- 3.6.5
- 3.6.4
- 3.6.3
- 3.6.2
- 3.6.1
- 3.6.0
- 3.6.0.CR1
- 3.5.3
- 3.5.2
- 3.5.1
- 3.5.0
- 3.5.0.CR1
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.4.0.CR1
- 3.3.3
- 3.3.2
- 3.3.1
- 3.3.0
- 3.3.0.CR1
- 3.2.12.Final
- 3.2.11.Final
- 3.2.10.Final
- 3.2.9.Final
- 3.2.8.Final
- 3.2.7.Final
- 3.2.6.Final
- 3.2.5.Final
- 3.2.4.Final
- 3.2.3.Final
- 3.2.2.Final
- 3.2.1.Final
- 3.2.0.Final
- 3.2.0.CR1
- 3.1.3.Final
- 3.1.2.Final
- 3.1.1.Final
- 3.1.0.Final
- 3.1.0.CR1
- 3.0.4.Final
- 3.0.3.Final
- 3.0.2.Final
- 3.0.1.Final
- 3.0.0.Final
- 3.0.0.CR2
- 3.0.0.CR1
- 3.0.0.Beta1
- 3.0.0.Alpha6
- 3.0.0.Alpha5
- 3.0.0.Alpha4
- 3.0.0.Alpha3
- 3.0.0.Alpha2
- 3.0.0.Alpha1
- 2.16.12.Final
- 2.16.11.Final
- 2.16.10.Final
- 2.16.9.Final
- 2.16.8.Final
- 2.16.7.Final
- 2.16.6.Final
- 2.16.5.Final
- 2.16.4.Final
- 2.16.3.Final
- 2.16.2.Final
- 2.16.1.Final
- 2.16.0.Final
- 2.16.0.CR1
- 2.15.3.Final
- 2.15.2.Final
- 2.15.1.Final
- 2.15.0.Final
- 2.15.0.CR1
- 2.14.3.Final
- 2.14.2.Final
- 2.14.1.Final
- 2.14.0.Final
- 2.14.0.CR1
- 2.13.9.Final
- 2.13.8.Final
- 2.13.7.Final
- 2.13.6.Final
- 2.13.5.Final
- 2.13.4.Final
- 2.13.3.Final
- 2.13.2.Final
- 2.13.1.Final
- 2.13.0.Final
- 2.13.0.CR1
- 2.12.3.Final
- 2.12.2.Final
- 2.12.1.Final
- 2.12.0.Final
- 2.12.0.CR1
- 2.11.3.Final
- 2.11.2.Final
- 2.11.1.Final
- 2.11.0.Final
- 2.11.0.CR1
- 2.10.4.Final
- 2.10.3.Final
- 2.10.2.Final
- 2.10.1.Final
- 2.10.0.Final
- 2.10.0.CR1
- 2.9.2.Final
- 2.9.1.Final
- 2.9.0.Final
- 2.9.0.CR1
- 2.8.3.Final
- 2.8.2.Final
- 2.8.1.Final
- 2.8.0.Final
- 2.8.0.CR1
- 2.7.7.Final
- 2.7.6.Final
- 2.7.5.Final
- 2.7.4.Final
- 2.7.3.Final
- 2.7.2.Final
- 2.7.1.Final
- 2.7.0.Final
- 2.7.0.CR1
- 2.6.3.Final
- 2.6.2.Final
- 2.6.1.Final
- 2.6.0.Final
- 2.6.0.CR1
- 2.5.4.Final
- 2.5.3.Final
- 2.5.2.Final
- 2.5.1.Final
- 2.5.0.Final
- 2.5.0.CR1
- 2.4.2.Final
- 2.4.1.Final
- 2.4.0.Final
- 2.4.0.CR1
- 2.3.1.Final
- 2.3.0.Final
- 2.3.0.CR1
- 2.2.5.Final
- 2.2.4.Final
- 2.2.3.Final
- 2.2.2.Final
- 2.2.1.Final
- 2.2.0.Final
- 2.2.0.CR1
Showing
13 changed files
with
260 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ernetes-client/src/test/java/io/quarkus/it/kubernetes/client/OpenShiftTestServerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package io.quarkus.it.kubernetes.client; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Base64; | ||
import java.util.function.Consumer; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.fabric8.kubernetes.api.model.ConfigMapBuilder; | ||
import io.fabric8.kubernetes.api.model.SecretBuilder; | ||
import io.fabric8.openshift.api.model.ProjectBuilder; | ||
import io.fabric8.openshift.client.OpenShiftClient; | ||
import io.fabric8.openshift.client.server.mock.OpenShiftServer; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.kubernetes.client.OpenShiftTestServer; | ||
import io.quarkus.test.kubernetes.client.WithOpenShiftTestServer; | ||
|
||
@WithOpenShiftTestServer(setup = OpenShiftTestServerTest.CrudEnvironmentPreparation.class) | ||
@QuarkusTest | ||
class OpenShiftTestServerTest { | ||
|
||
@OpenShiftTestServer | ||
private OpenShiftServer mockServer; | ||
|
||
@Inject | ||
OpenShiftClient client; | ||
|
||
@Test | ||
void testInjectionDefaultsToCrud() { | ||
mockServer.getOpenshiftClient().projects().createOrReplace(new ProjectBuilder() | ||
.withNewMetadata().withName("example-project").addToLabels("project", "crud-is-true").endMetadata() | ||
.build()); | ||
assertThat(client) | ||
.isNotSameAs(mockServer.getOpenshiftClient()) | ||
.isNotSameAs(mockServer.getOpenshiftClient()) | ||
.returns("crud-is-true", | ||
c -> c.projects().withName("example-project").get().getMetadata().getLabels().get("project")); | ||
} | ||
|
||
public static final class CrudEnvironmentPreparation implements Consumer<OpenShiftServer> { | ||
|
||
@Override | ||
public void accept(OpenShiftServer openShiftServer) { | ||
final OpenShiftClient oc = openShiftServer.getOpenshiftClient(); | ||
oc.configMaps().createOrReplace(new ConfigMapBuilder() | ||
.withNewMetadata().withName("cmap1").endMetadata() | ||
.addToData("dummy", "I'm required") | ||
.build()); | ||
oc.configMaps().createOrReplace(new ConfigMapBuilder() | ||
.withNewMetadata().withName("cmap2").endMetadata() | ||
.addToData("dummysecret", "dumb") | ||
.addToData("overridden.secret", "Alex") | ||
.addToData("some.prop1", "I'm required") | ||
.addToData("some.prop2", "I'm required (2)") | ||
.addToData("some.prop3", "I'm required (3)") | ||
.addToData("some.prop4", "I'm required (4)") | ||
.addToData("some.prop5", "I'm required (5)") | ||
.build()); | ||
oc.secrets().createOrReplace(new SecretBuilder() | ||
.withNewMetadata().withName("s1").endMetadata() | ||
.addToData("secret.prop1", encodeValue("s1cret")) | ||
.addToData("secret.prop2", encodeValue("s2cret")) | ||
.addToData("secret.prop3", encodeValue("s3cret")) | ||
.addToData("secret.prop4", encodeValue("s4cret")) | ||
.build()); | ||
} | ||
} | ||
|
||
private static String encodeValue(String value) { | ||
return Base64.getEncoder().encodeToString(value.getBytes()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...t-client/src/main/java/io/quarkus/test/kubernetes/client/OpenShiftServerTestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package io.quarkus.test.kubernetes.client; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.function.Consumer; | ||
|
||
import io.fabric8.kubernetes.client.GenericKubernetesClient; | ||
import io.fabric8.openshift.client.NamespacedOpenShiftClient; | ||
import io.fabric8.openshift.client.server.mock.OpenShiftServer; | ||
import io.quarkus.test.common.QuarkusTestResourceConfigurableLifecycleManager; | ||
|
||
public class OpenShiftServerTestResource extends AbstractKubernetesTestResource<OpenShiftServer, NamespacedOpenShiftClient> | ||
implements QuarkusTestResourceConfigurableLifecycleManager<WithOpenShiftTestServer> { | ||
|
||
private boolean https = false; | ||
private boolean crud = true; | ||
private Consumer<OpenShiftServer> setup; | ||
|
||
@Override | ||
public void init(WithOpenShiftTestServer annotation) { | ||
this.https = annotation.https(); | ||
this.crud = annotation.crud(); | ||
try { | ||
this.setup = annotation.setup().getDeclaredConstructor().newInstance(); | ||
} catch (ReflectiveOperationException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
protected GenericKubernetesClient<NamespacedOpenShiftClient> getClient() { | ||
return server.getOpenshiftClient(); | ||
} | ||
|
||
@Override | ||
protected void initServer() { | ||
server.before(); | ||
} | ||
|
||
@Override | ||
protected void configureServer() { | ||
if (setup != null) | ||
setup.accept(server); | ||
} | ||
|
||
@Override | ||
protected OpenShiftServer createServer() { | ||
return new OpenShiftServer(https, crud); | ||
} | ||
|
||
@Override | ||
public void stop() { | ||
if (server != null) { | ||
server.after(); | ||
server = null; | ||
} | ||
} | ||
|
||
@Override | ||
protected Class<?> getInjectedClass() { | ||
return OpenShiftServer.class; | ||
} | ||
|
||
@Override | ||
protected Class<? extends Annotation> getInjectionAnnotation() { | ||
return OpenShiftTestServer.class; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...openshift-client/src/main/java/io/quarkus/test/kubernetes/client/OpenShiftTestServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
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.openshift.client.server.mock.OpenShiftServer; | ||
|
||
/** | ||
* Used to specify that the field should be injected with the mock OpenShift API server | ||
* Can only be used on type {@link OpenShiftServer} | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.FIELD) | ||
public @interface OpenShiftTestServer { | ||
} |
41 changes: 41 additions & 0 deletions
41
...shift-client/src/main/java/io/quarkus/test/kubernetes/client/WithOpenShiftTestServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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 java.util.function.Consumer; | ||
|
||
import io.fabric8.openshift.client.server.mock.OpenShiftServer; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
|
||
/** | ||
* Use on your test resource to get a mock {@link OpenShiftServer} spawn up, and injectable with {@link OpenShiftTestServer}. | ||
* This annotation is only active when used on a test class, and only for this test class. | ||
*/ | ||
@QuarkusTestResource(value = OpenShiftServerTestResource.class, restrictToAnnotatedClass = true) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface WithOpenShiftTestServer { | ||
|
||
/** | ||
* Start it with HTTPS | ||
*/ | ||
boolean https() default false; | ||
|
||
/** | ||
* Start it in CRUD mode | ||
*/ | ||
boolean crud() default true; | ||
|
||
/** | ||
* Setup class to call after the mock server is created, for custom setup. | ||
*/ | ||
Class<? extends Consumer<OpenShiftServer>> setup() default NO_SETUP.class; | ||
|
||
class NO_SETUP implements Consumer<OpenShiftServer> { | ||
@Override | ||
public void accept(OpenShiftServer t) { | ||
} | ||
} | ||
} |