Skip to content

Commit

Permalink
Enable Postgres service binding tests
Browse files Browse the repository at this point in the history
Enables PG SB test as quarkusio/quarkus#37461 is fixed, run it against 4.14 from my workstation and works. Ports quarkus-qe#1547 as the test fails without it.
  • Loading branch information
michalvavrik committed Jan 8, 2024
1 parent 0ef1ac5 commit 0008966
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
package io.quarkus.ts.sb.postgresql;

import static io.quarkus.test.utils.AwaitilityUtils.untilAsserted;
import static io.quarkus.test.utils.AwaitilityUtils.AwaitilitySettings.using;
import static java.time.Duration.ofSeconds;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import jakarta.inject.Inject;

import org.apache.http.HttpStatus;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.RestService;
Expand All @@ -22,7 +24,6 @@
import io.quarkus.test.utils.Command;

@OpenShiftScenario(deployment = OpenShiftDeploymentStrategy.UsingOpenShiftExtensionAndDockerBuildStrategy)
@Disabled("https://github.com/quarkusio/quarkus/issues/34759")
public class OpenShiftPostgreSqlSbIT {

@Inject
Expand All @@ -49,22 +50,23 @@ public void verifyPostgresServiceBoundToApplication() {
.statusCode(HttpStatus.SC_OK);
}

private static boolean areRequiredOperatorsInstalled() {
List<String> output = new ArrayList<>();
try {
// TODO: figure out a better way to wait for this - this wait is necessary as it takes some time for API to
// populate new namespace with objects
Thread.sleep(2000);
new Command("oc", "get", "csv").outputToLines(output).runAndWait();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
String outputString = output.stream().collect(Collectors.joining(System.lineSeparator()));
return (outputString.contains("postgresoperator") && outputString.contains("service-binding-operator"));
private static void assertRequiredOperatorsInstalled() {
untilAsserted(() -> {
List<String> output = new ArrayList<>();
try {
// TODO: figure out a better way to wait for this - this wait is necessary as it takes some
// time for API to populate new namespace with objects
new Command("oc", "get", "csv").outputToLines(output).runAndWait();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
assertTrue(output.stream().anyMatch(str -> str.contains("postgresoperator")));
assertTrue(output.stream().anyMatch(str -> str.contains("service-binding-operator")));
}, using(ofSeconds(2), ofSeconds(60)));
}

private static void createPostgresCluster() {
Assumptions.assumeTrue(areRequiredOperatorsInstalled());
assertRequiredOperatorsInstalled();
applyCustomResourceDefinition("pg-cluster.yml");
try {
// TODO: figure out a better way to wait for this - sometimes operator takes a while to create object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package io.quarkus.ts.sb.reactive;

import static io.quarkus.test.utils.AwaitilityUtils.untilAsserted;
import static io.quarkus.test.utils.AwaitilityUtils.AwaitilitySettings.using;
import static java.time.Duration.ofSeconds;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import jakarta.inject.Inject;

import org.apache.http.HttpStatus;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import io.quarkus.test.bootstrap.RestService;
Expand All @@ -23,7 +25,6 @@
import io.quarkus.test.utils.Command;

@OpenShiftScenario(deployment = OpenShiftDeploymentStrategy.UsingOpenShiftExtensionAndDockerBuildStrategy)
@Disabled("https://github.com/quarkusio/quarkus/issues/34759")
public class OpenShiftPostgreSqlReactiveSbIT {

private static final String PG_CLUSTER_YML = "pg-cluster.yml";
Expand Down Expand Up @@ -53,22 +54,23 @@ public void verifyPostgresServiceBoundToApplication() {
.body("title", Matchers.equalTo("Finish the blog post"));
}

private static boolean areRequiredOperatorsInstalled() {
List<String> output = new ArrayList<>();
try {
// TODO: figure out a better way to wait for this - this wait is necessary as it takes some time for API to
// populate new namespace with objects
Thread.sleep(2000);
new Command("oc", "get", "csv").outputToLines(output).runAndWait();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
String outputString = output.stream().collect(Collectors.joining(System.lineSeparator()));
return (outputString.contains("postgresoperator") && outputString.contains("service-binding-operator"));
private static void assertRequiredOperatorsInstalled() {
untilAsserted(() -> {
List<String> output = new ArrayList<>();
try {
// TODO: figure out a better way to wait for this - this wait is necessary as it takes some
// time for API to populate new namespace with objects
new Command("oc", "get", "csv").outputToLines(output).runAndWait();
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
assertTrue(output.stream().anyMatch(str -> str.contains("postgresoperator")));
assertTrue(output.stream().anyMatch(str -> str.contains("service-binding-operator")));
}, using(ofSeconds(2), ofSeconds(60)));
}

private static void createPostgresCluster() {
Assumptions.assumeTrue(areRequiredOperatorsInstalled());
assertRequiredOperatorsInstalled();
applyCustomResourceDefinition();
try {
// TODO: figure out a better way to wait for this - sometimes operator takes a while to create object
Expand Down

0 comments on commit 0008966

Please sign in to comment.