Skip to content

Commit

Permalink
Merge pull request #45443 from manusa/fix/openshift-mock-server
Browse files Browse the repository at this point in the history
Remove references to removed WithOpenShiftTestServer functionality
  • Loading branch information
gsmet authored Jan 8, 2025
2 parents 9f8415e + a07da0c commit dbdfcea
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 30 deletions.
36 changes: 15 additions & 21 deletions docs/src/main/asciidoc/kubernetes-client.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -474,49 +474,43 @@ public class OpenShiftClientProducer {
}
----

Mock support is also provided in a similar fashion:
Mock support is also provided in a similar fashion by using the `@WithKubernetesTestServer` explained in the previous section:

[source, java]
----
@QuarkusTestResource(OpenShiftMockServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
public class OpenShiftClientTest {
@MockServer
private OpenShiftMockServer mockServer;
...
----

Or by using the `@WithOpenShiftTestServer` similar to the `@WithKubernetesTestServer` explained in the
previous section:

[source, java]
----
@WithOpenShiftTestServer
@QuarkusTest
public class OpenShiftClientTest {
@KubernetesTestServer
KubernetesServer mockServer;
@Inject
OpenShiftClient client;
@OpenShiftTestServer
private OpenShiftServer mockOpenShiftServer;
...
@Test
public void testInteractionWithAPIServer() {
RestAssured.when().get("/route/test").then()
.body("size()", is(2));
}
}
----

To use this feature, you have to add a dependency on `quarkus-test-openshift-client`:
To use this feature, you have to add a dependency on `quarkus-test-kubernetes-client`:

[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"]
.pom.xml
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-test-openshift-client</artifactId>
<artifactId>quarkus-test-kubernetes-client</artifactId>
<scope>test</scope>
</dependency>
----

[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"]
.build.gradle
----
testImplementation("io.quarkus:quarkus-test-openshift-client")
testImplementation("io.quarkus:quarkus-test-kubernetes-client")
----

== Configuration Reference
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.quarkus.it.openshift.client;

import static org.assertj.core.api.Assertions.assertThat;

import jakarta.inject.Inject;

import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.NonDeletingOperation;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.fabric8.openshift.api.model.RouteBuilder;
import io.fabric8.openshift.client.OpenShiftClient;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;

@WithKubernetesTestServer
@QuarkusTest
public class KubernetesTestServerTest {

@KubernetesTestServer
KubernetesServer mockServer;
@Inject
KubernetesClient kubernetesClient;
@Inject
OpenShiftClient openShiftClient;

@Test
public void clientsInjectedWithValidConfiguration() {
assertThat(kubernetesClient)
.isSameAs(openShiftClient)
.extracting(c -> c.getConfiguration().getMasterUrl())
.isEqualTo(mockServer.getKubernetesMockServer().url("/"));
}

@Test
public void openShiftClientInjectionWorks() throws InterruptedException {
openShiftClient.routes().resource(
new RouteBuilder()
.withNewMetadata().withName("the-route").endMetadata()
.withNewSpec().withHost("example.com").endSpec()
.build())
.createOr(NonDeletingOperation::update);
assertThat(mockServer.getLastRequest().getPath())
.isEqualTo("/apis/route.openshift.io/v1/namespaces/test/routes");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
import org.junit.jupiter.api.Test;

import io.fabric8.kubernetes.api.model.PodListBuilder;
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
import io.fabric8.kubernetes.client.server.mock.KubernetesServer;
import io.fabric8.openshift.api.model.Route;
import io.fabric8.openshift.api.model.RouteBuilder;
import io.fabric8.openshift.client.NamespacedOpenShiftClient;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.kubernetes.client.KubernetesMockServerTestResource;
import io.quarkus.test.kubernetes.client.MockServer;
import io.quarkus.test.kubernetes.client.KubernetesTestServer;
import io.quarkus.test.kubernetes.client.WithKubernetesTestServer;
import io.restassured.RestAssured;

@QuarkusTestResource(KubernetesMockServerTestResource.class)
@WithKubernetesTestServer
@QuarkusTest
public class OpenShiftClientTest {

@MockServer
private KubernetesMockServer mockServer;
@KubernetesTestServer
KubernetesServer mockServer;

@Test
void createRoute() {
Expand All @@ -36,9 +35,10 @@ void createRoute() {
.andReturn(200, expectedRoute)
.once();

NamespacedOpenShiftClient openShiftClient = mockServer.createClient().adapt(NamespacedOpenShiftClient.class);
NamespacedOpenShiftClient openShiftClient = mockServer.getClient().adapt(NamespacedOpenShiftClient.class);
openShiftClient.routes()
.create(new RouteBuilder().withNewMetadata().withName("myroute").withNamespace("test").endMetadata().build());
.resource(new RouteBuilder().withNewMetadata().withName("myroute").withNamespace("test").endMetadata().build())
.create();
Route route = openShiftClient.routes().inNamespace("test").withName("myroute").get();
Assertions.assertNotNull(route);
}
Expand Down

0 comments on commit dbdfcea

Please sign in to comment.