Skip to content

Commit dd29a99

Browse files
authored
migrate webpage (#43)
Signed-off-by: csviri <[email protected]>
1 parent ca83e64 commit dd29a99

File tree

2 files changed

+81
-66
lines changed

2 files changed

+81
-66
lines changed

src/test/java/io/csviri/operator/resourceglue/TestBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
1212
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
1313
import io.fabric8.kubernetes.client.KubernetesClient;
14+
import io.fabric8.kubernetes.client.dsl.NonDeletingOperation;
1415
import io.fabric8.kubernetes.client.utils.KubernetesResourceUtil;
1516

1617
import jakarta.inject.Inject;
@@ -54,6 +55,11 @@ protected <T extends HasMetadata> T create(T resource) {
5455
return client.resource(resource).inNamespace(testNamespace).create();
5556
}
5657

58+
protected <T extends HasMetadata> T createOrUpdate(T resource) {
59+
return client.resource(resource).inNamespace(testNamespace)
60+
.createOr(NonDeletingOperation::update);
61+
}
62+
5763
protected <T extends HasMetadata> T get(Class<T> clazz, String name) {
5864
return client.resources(clazz).inNamespace(testNamespace).withName(name).get();
5965
}
Lines changed: 75 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,78 @@
11
package io.csviri.operator.resourceglue.sample.webpage;
22

3-
public class WebPageSampleTest {
4-
5-
// todo
6-
7-
// @RegisterExtension
8-
// LocallyRunOperatorExtension extension =
9-
// LocallyRunOperatorExtension.builder()
10-
// .withReconciler(new GlueReconciler())
11-
// .withReconciler(new GlueOperatorReconciler())
12-
// .build();
13-
//
14-
// @Test
15-
// void webPageCRUD() {
16-
// TestUtils.createOrUpdate(extension, "/sample/webpage/webpage.crd.yml");
17-
// TestUtils.createOrUpdate(extension, "/sample/webpage/webpage.operator.yaml");
18-
// var webPage = TestUtils.createOrUpdate(extension, "/sample/webpage/webpage.sample.yaml");
19-
//
20-
// await().untilAsserted(() -> {
21-
// var deployment = extension.get(Deployment.class, webPage.getMetadata().getName());
22-
// var configMap = extension.get(ConfigMap.class, webPage.getMetadata().getName());
23-
// var service = extension.get(Service.class, webPage.getMetadata().getName());
24-
// var ingress = extension.get(Ingress.class, webPage.getMetadata().getName());
25-
//
26-
// assertThat(ingress).isNull();
27-
// assertThat(deployment).isNotNull();
28-
// assertThat(service).isNotNull();
29-
// assertThat(configMap).isNotNull();
30-
// assertThat(configMap.getData().get("index.html")).contains("Hello World!");
31-
// });
32-
//
33-
// setExposed(webPage);
34-
// setNewHtml(webPage);
35-
// extension.replace(webPage);
36-
//
37-
// await().untilAsserted(() -> {
38-
// var ingress = extension.get(Ingress.class, webPage.getMetadata().getName());
39-
// var configMap = extension.get(ConfigMap.class, webPage.getMetadata().getName());
40-
//
41-
// assertThat(configMap.getData().get("index.html")).contains("Hello World 2!");
42-
// assertThat(ingress).isNotNull();
43-
// });
44-
//
45-
// extension.delete(webPage);
46-
//
47-
// await().untilAsserted(() -> {
48-
// var deployment = extension.get(Deployment.class, webPage.getMetadata().getName());
49-
// assertThat(deployment).isNull();
50-
// });
51-
// }
52-
//
53-
// private void setNewHtml(GenericKubernetesResource webPage) {
54-
// ((HashMap<String, Object>) webPage.getAdditionalProperties().get("spec")).put("html", """
55-
// <html>
56-
// <head>
57-
// <title>Hello Operator World</title>
58-
// </head>
59-
// <body>
60-
// Hello World 2!
61-
// </body>
62-
// </html>
63-
// """);
64-
// }
65-
//
66-
// private void setExposed(GenericKubernetesResource webPage) {
67-
// ((HashMap<String, Object>) webPage.getAdditionalProperties().get("spec")).put("exposed", true);
68-
// }
3+
import java.util.HashMap;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import io.csviri.operator.resourceglue.TestBase;
8+
import io.csviri.operator.resourceglue.TestUtils;
9+
import io.fabric8.kubernetes.api.model.ConfigMap;
10+
import io.fabric8.kubernetes.api.model.GenericKubernetesResource;
11+
import io.fabric8.kubernetes.api.model.Service;
12+
import io.fabric8.kubernetes.api.model.apps.Deployment;
13+
import io.fabric8.kubernetes.api.model.networking.v1.Ingress;
14+
import io.quarkus.test.junit.QuarkusTest;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
import static org.awaitility.Awaitility.await;
18+
19+
@QuarkusTest
20+
public class WebPageSampleTest extends TestBase {
21+
22+
@Test
23+
void webPageCRUD() {
24+
25+
createOrUpdate(TestUtils.load("/sample/webpage/webpage.crd.yml"));
26+
createOrUpdate(TestUtils.load("/sample/webpage/webpage.operator.yaml"));
27+
var webPage = createOrUpdate(TestUtils.load("/sample/webpage/webpage.sample.yaml"));
28+
29+
await().untilAsserted(() -> {
30+
var deployment = get(Deployment.class, webPage.getMetadata().getName());
31+
var configMap = get(ConfigMap.class, webPage.getMetadata().getName());
32+
var service = get(Service.class, webPage.getMetadata().getName());
33+
var ingress = get(Ingress.class, webPage.getMetadata().getName());
34+
35+
assertThat(ingress).isNull();
36+
assertThat(deployment).isNotNull();
37+
assertThat(service).isNotNull();
38+
assertThat(configMap).isNotNull();
39+
assertThat(configMap.getData().get("index.html")).contains("Hello World!");
40+
});
41+
42+
setExposed(webPage);
43+
setNewHtml(webPage);
44+
update(webPage);
45+
46+
await().untilAsserted(() -> {
47+
var ingress = get(Ingress.class, webPage.getMetadata().getName());
48+
var configMap = get(ConfigMap.class, webPage.getMetadata().getName());
49+
50+
assertThat(configMap.getData().get("index.html")).contains("Hello World 2!");
51+
assertThat(ingress).isNotNull();
52+
});
53+
54+
delete(webPage);
55+
56+
await().untilAsserted(() -> {
57+
var deployment = get(Deployment.class, webPage.getMetadata().getName());
58+
assertThat(deployment).isNull();
59+
});
60+
}
61+
62+
private void setNewHtml(GenericKubernetesResource webPage) {
63+
((HashMap<String, Object>) webPage.getAdditionalProperties().get("spec")).put("html", """
64+
<html>
65+
<head>
66+
<title>Hello Operator World</title>
67+
</head>
68+
<body>
69+
Hello World 2!
70+
</body>
71+
</html>
72+
""");
73+
}
74+
75+
private void setExposed(GenericKubernetesResource webPage) {
76+
((HashMap<String, Object>) webPage.getAdditionalProperties().get("spec")).put("exposed", true);
77+
}
6978
}

0 commit comments

Comments
 (0)