-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
204 additions
and
0 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
24 changes: 24 additions & 0 deletions
24
sql-db/panache-flyway/src/test/java/io/quarkus/ts/sqldb/panacheflyway/init/CustomYaml.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,24 @@ | ||
package io.quarkus.ts.sqldb.panacheflyway.init; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Map; | ||
|
||
class CustomYaml { | ||
private final Map content; | ||
|
||
CustomYaml(Object content) { | ||
this.content = (Map) content; | ||
} | ||
|
||
CustomYaml get(String name) { | ||
return new CustomYaml(this.content.get(name)); | ||
} | ||
|
||
String getValue(String name) { | ||
return (String) this.content.get(name); | ||
} | ||
|
||
public CustomYaml getFromArray(String name, int i) { | ||
return new CustomYaml(((ArrayList) this.content.get(name)).get(i)); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
...src/test/java/io/quarkus/ts/sqldb/panacheflyway/init/OpenShiftDefaultInitContainerIT.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,74 @@ | ||
package io.quarkus.ts.sqldb.panacheflyway.init; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import io.quarkus.test.bootstrap.MySqlService; | ||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.OpenShiftDeploymentStrategy; | ||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
import io.quarkus.test.services.Container; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
|
||
@OpenShiftScenario(deployment = OpenShiftDeploymentStrategy.UsingOpenShiftExtension) | ||
public class OpenShiftDefaultInitContainerIT { | ||
|
||
private final Path openShiftYaml = Paths.get("target/", this.getClass().getSimpleName(), | ||
"app/target/kubernetes/openshift.yml"); | ||
private static final String CUSTOM_IMAGE = "quay.io/quarkusqeteam/wait:0.0.2"; | ||
|
||
@Container(image = "${mysql.80.image}", port = 3306, expectedLog = "Only MySQL server logs after this point") | ||
static MySqlService database = new MySqlService(); | ||
|
||
@QuarkusApplication | ||
static RestService app = new RestService() | ||
.withProperty("quarkus.datasource.username", database.getUser()) | ||
.withProperty("quarkus.datasource.password", database.getPassword()) | ||
.withProperty("quarkus.datasource.jdbc.url", database::getJdbcUrl) | ||
.withProperty("quarkus.openshift.init-task-defaults.wait-for-container.image", CUSTOM_IMAGE) | ||
.withProperty("quarkus.flyway.schemas", database.getDatabase()); | ||
|
||
@Test | ||
@Disabled | ||
void migrated() { | ||
String userList = app.given() | ||
.accept("application/hal+json") | ||
.when().get("/users/all?sort=name") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.extract().response().jsonPath().getString("_embedded.user_list.name"); | ||
assertEquals("[Alaba, Balaba]", userList); | ||
} | ||
|
||
@Test | ||
void yaml() { | ||
try (InputStream content = Files.newInputStream(openShiftYaml)) { | ||
Iterable<Object> objects = new Yaml().loadAll(content); | ||
String image = null; | ||
for (Object object : objects) { | ||
CustomYaml source = new CustomYaml(object); | ||
if ("Deployment".equals(source.getValue("kind"))) { | ||
image = source.get("spec") | ||
.get("template") | ||
.get("spec") | ||
.getFromArray("initContainers", 0) | ||
.getValue("image"); | ||
} | ||
} | ||
Assertions.assertEquals(CUSTOM_IMAGE, image); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
.../src/test/java/io/quarkus/ts/sqldb/panacheflyway/init/OpenShiftFlywayInitContainerIT.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,77 @@ | ||
package io.quarkus.ts.sqldb.panacheflyway.init; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import io.quarkus.test.bootstrap.MySqlService; | ||
import io.quarkus.test.bootstrap.RestService; | ||
import io.quarkus.test.scenarios.OpenShiftDeploymentStrategy; | ||
import io.quarkus.test.scenarios.OpenShiftScenario; | ||
import io.quarkus.test.services.Container; | ||
import io.quarkus.test.services.QuarkusApplication; | ||
|
||
@OpenShiftScenario(deployment = OpenShiftDeploymentStrategy.UsingOpenShiftExtension) | ||
@Disabled("https://github.com/quarkusio/quarkus/issues/39230") | ||
public class OpenShiftFlywayInitContainerIT { | ||
|
||
private final Path openShiftYaml = Paths.get("target/", this.getClass().getSimpleName(), | ||
"app/target/kubernetes/openshift.yml"); | ||
private static final String CUSTOM_IMAGE = "quay.io/quarkusqeteam/wait"; | ||
|
||
@Container(image = "${mysql.80.image}", port = 3306, expectedLog = "Only MySQL server logs after this point") | ||
static MySqlService database = new MySqlService(); | ||
|
||
@QuarkusApplication | ||
static RestService app = new RestService() | ||
.withProperty("quarkus.datasource.username", database.getUser()) | ||
.withProperty("quarkus.datasource.password", database.getPassword()) | ||
.withProperty("quarkus.datasource.jdbc.url", database::getJdbcUrl) | ||
.withProperty("quarkus.openshift.init-containers.wait-for-flyway.image", CUSTOM_IMAGE) | ||
.withProperty("quarkus.openshift.init-containers.wait-for-flyway.image-pull-policy", "Always") | ||
.withProperty("quarkus.flyway.schemas", database.getDatabase()); | ||
|
||
@Test | ||
@Disabled | ||
void migrated() { | ||
String userList = app.given() | ||
.accept("application/hal+json") | ||
.when().get("/users/all?sort=name") | ||
.then() | ||
.statusCode(HttpStatus.SC_OK) | ||
.extract().response().jsonPath().getString("_embedded.user_list.name"); | ||
assertEquals("[Alaba, Balaba]", userList); | ||
} | ||
|
||
@Test | ||
void yaml() { | ||
try (InputStream content = Files.newInputStream(openShiftYaml)) { | ||
Iterable<Object> objects = new Yaml().loadAll(content); | ||
CustomYaml initContainer = null; | ||
for (Object object : objects) { | ||
CustomYaml source = new CustomYaml(object); | ||
if ("Deployment".equals(source.getValue("kind"))) { | ||
initContainer = source.get("spec") | ||
.get("template") | ||
.get("spec") | ||
.getFromArray("initContainers", 0); | ||
} | ||
} | ||
Assertions.assertNotNull(initContainer); | ||
Assertions.assertEquals(CUSTOM_IMAGE, initContainer.getValue("image")); | ||
Assertions.assertEquals("Always", initContainer.getValue("imagePullPolicy")); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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,16 @@ | ||
#!/usr/bin/env -S podman build . --tag quay.io/quarkusqeteam/wait:0.0.2 --file | ||
FROM ubi8:latest | ||
|
||
COPY <<EOF /etc/yum.repos.d/kubernetes.repo | ||
[kubernetes] | ||
name=Kubernetes | ||
baseurl=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/ | ||
enabled=1 | ||
gpgcheck=1 | ||
gpgkey=https://pkgs.k8s.io/core:/stable:/v1.29/rpm/repodata/repomd.xml.key | ||
EOF | ||
RUN dnf -y install kubectl | ||
|
||
ADD --chmod=777 https://raw.githubusercontent.com/groundnuty/k8s-wait-for/master/wait_for.sh /usr/local/bin/wait_for.sh | ||
|
||
ENTRYPOINT ["wait_for.sh"] |