Skip to content

Commit b3066f2

Browse files
committed
chore: move integration tests to runtime-configuration module
operator-framework module now also creates a jar out of its test classes for reuse purposes. This should probably be extracted more cleanly at some point.
1 parent 8f1c8de commit b3066f2

File tree

10 files changed

+93
-86
lines changed

10 files changed

+93
-86
lines changed

operator-framework/pom.xml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
<artifactId>maven-surefire-plugin</artifactId>
2929
<version>${surefire.version}</version>
3030
</plugin>
31+
<plugin>
32+
<groupId>org.apache.maven.plugins</groupId>
33+
<artifactId>maven-jar-plugin</artifactId>
34+
<version>3.2.0</version>
35+
<executions>
36+
<execution>
37+
<goals>
38+
<goal>test-jar</goal>
39+
</goals>
40+
</execution>
41+
</executions>
42+
</plugin>
3143
</plugins>
3244
</build>
3345

@@ -42,10 +54,6 @@
4254
<groupId>io.fabric8</groupId>
4355
<artifactId>openshift-client</artifactId>
4456
</dependency>
45-
<!--<dependency>
46-
<groupId>org.apache.commons</groupId>
47-
<artifactId>commons-lang3</artifactId>
48-
</dependency>-->
4957
<dependency>
5058
<groupId>org.slf4j</groupId>
5159
<artifactId>slf4j-api</artifactId>
@@ -78,24 +86,5 @@
7886
<version>3.18.0</version>
7987
<scope>test</scope>
8088
</dependency>
81-
<dependency>
82-
<groupId>org.awaitility</groupId>
83-
<artifactId>awaitility</artifactId>
84-
<version>4.0.3</version>
85-
<scope>test</scope>
86-
</dependency>
87-
<dependency>
88-
<groupId>com.google.testing.compile</groupId>
89-
<artifactId>compile-testing</artifactId>
90-
<version>0.19</version>
91-
<scope>test</scope>
92-
</dependency>
93-
94-
<dependency>
95-
<groupId>io.javaoperatorsdk</groupId>
96-
<artifactId>runtime-configuration</artifactId>
97-
<version>${project.version}</version>
98-
<scope>test</scope>
99-
</dependency>
10089
</dependencies>
10190
</project>

operator-framework/src/test/java/io/javaoperatorsdk/operator/TestUtils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public class TestUtils {
1010

1111
public static final String TEST_CUSTOM_RESOURCE_NAME = "test-custom-resource";
12+
public static final String TEST_NAMESPACE = "java-operator-sdk-int-test";
1213

1314
public static TestCustomResource testCustomResource() {
1415
return testCustomResource(UUID.randomUUID().toString());
@@ -21,7 +22,7 @@ public static TestCustomResource testCustomResource(String uid) {
2122
.withName(TEST_CUSTOM_RESOURCE_NAME)
2223
.withUid(uid)
2324
.withGeneration(1L)
24-
.withNamespace(IntegrationTestSupport.TEST_NAMESPACE)
25+
.withNamespace(TEST_NAMESPACE)
2526
.build());
2627
resource.getMetadata().setAnnotations(new HashMap<>());
2728
resource.setKind("CustomService");

operator-framework/src/test/java/io/javaoperatorsdk/operator/processing/event/EventListTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package io.javaoperatorsdk.operator.processing.event;
22

3-
import static com.google.common.truth.Truth.assertThat;
43
import static org.mockito.Mockito.mock;
54

65
import io.javaoperatorsdk.operator.api.Event;
76
import io.javaoperatorsdk.operator.api.EventList;
87
import io.javaoperatorsdk.operator.processing.event.internal.TimerEvent;
98
import java.util.Arrays;
9+
import org.assertj.core.api.Assertions;
1010
import org.junit.jupiter.api.Test;
1111

1212
class EventListTest {
@@ -18,6 +18,6 @@ public void returnsLatestOfEventType() {
1818
new EventList(
1919
Arrays.asList(mock(Event.class), new TimerEvent("2", null), event2, mock(Event.class)));
2020

21-
assertThat(eventList.getLatestOfType(TimerEvent.class).get()).isSameInstanceAs(event2);
21+
Assertions.assertThat(eventList.getLatestOfType(TimerEvent.class).get()).isEqualTo(event2);
2222
}
2323
}

runtime-configuration/pom.xml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependencies>
2121
<dependency>
2222
<groupId>io.javaoperatorsdk</groupId>
23-
<artifactId>api</artifactId>
23+
<artifactId>operator-framework</artifactId>
2424
<version>${project.version}</version>
2525
</dependency>
2626
<dependency>
@@ -55,12 +55,31 @@
5555
<artifactId>junit-jupiter-engine</artifactId>
5656
<scope>test</scope>
5757
</dependency>
58+
<dependency>
59+
<groupId>org.assertj</groupId>
60+
<artifactId>assertj-core</artifactId>
61+
<version>3.18.0</version>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.awaitility</groupId>
66+
<artifactId>awaitility</artifactId>
67+
<version>4.0.3</version>
68+
<scope>test</scope>
69+
</dependency>
5870
<dependency>
5971
<groupId>com.google.testing.compile</groupId>
6072
<artifactId>compile-testing</artifactId>
6173
<version>0.19</version>
6274
<scope>test</scope>
6375
</dependency>
76+
<dependency>
77+
<groupId>io.javaoperatorsdk</groupId>
78+
<artifactId>operator-framework</artifactId>
79+
<version>${project.version}</version>
80+
<classifier>tests</classifier>
81+
<type>test-jar</type>
82+
</dependency>
6483
</dependencies>
6584

6685
</project>

operator-framework/src/test/java/io/javaoperatorsdk/operator/ConcurrencyIT.java renamed to runtime-configuration/src/test/java/io/javaoperatorsdk/operator/ConcurrencyIT.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package io.javaoperatorsdk.operator;
22

3-
import static org.assertj.core.api.Assertions.assertThat;
4-
53
import io.fabric8.kubernetes.api.model.ConfigMap;
64
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
75
import io.fabric8.kubernetes.client.KubernetesClient;
@@ -10,6 +8,7 @@
108
import java.util.List;
119
import java.util.concurrent.TimeUnit;
1210
import java.util.stream.Collectors;
11+
import org.assertj.core.api.Assertions;
1312
import org.awaitility.Awaitility;
1413
import org.junit.jupiter.api.BeforeAll;
1514
import org.junit.jupiter.api.BeforeEach;
@@ -66,7 +65,7 @@ public void manyResourcesGetCreatedUpdatedAndDeleted() {
6665
"managedBy", TestCustomResourceController.class.getSimpleName())
6766
.list()
6867
.getItems();
69-
assertThat(items).hasSize(NUMBER_OF_RESOURCES_CREATED);
68+
Assertions.assertThat(items).hasSize(NUMBER_OF_RESOURCES_CREATED);
7069
});
7170

7271
log.info("Updating {} resources", NUMBER_OF_RESOURCES_UPDATED);
@@ -116,7 +115,7 @@ public void manyResourcesGetCreatedUpdatedAndDeleted() {
116115
items.stream()
117116
.map(configMap -> configMap.getMetadata().getName())
118117
.collect(Collectors.toList());
119-
assertThat(itemDescs)
118+
Assertions.assertThat(itemDescs)
120119
.hasSize(NUMBER_OF_RESOURCES_CREATED - NUMBER_OF_RESOURCES_DELETED);
121120

122121
List<TestCustomResource> crs =
@@ -125,7 +124,7 @@ public void manyResourcesGetCreatedUpdatedAndDeleted() {
125124
.inNamespace(IntegrationTestSupport.TEST_NAMESPACE)
126125
.list()
127126
.getItems();
128-
assertThat(crs)
127+
Assertions.assertThat(crs)
129128
.hasSize(NUMBER_OF_RESOURCES_CREATED - NUMBER_OF_RESOURCES_DELETED);
130129
});
131130
});

operator-framework/src/test/java/io/javaoperatorsdk/operator/ControllerExecutionIT.java renamed to runtime-configuration/src/test/java/io/javaoperatorsdk/operator/ControllerExecutionIT.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package io.javaoperatorsdk.operator;
22

3-
import static io.javaoperatorsdk.operator.TestUtils.TEST_CUSTOM_RESOURCE_NAME;
4-
import static io.javaoperatorsdk.operator.TestUtils.testCustomResource;
5-
import static org.assertj.core.api.Assertions.assertThat;
6-
import static org.awaitility.Awaitility.await;
7-
83
import io.fabric8.kubernetes.api.model.ConfigMap;
94
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
105
import io.fabric8.kubernetes.client.KubernetesClient;
116
import io.javaoperatorsdk.operator.sample.simple.TestCustomResource;
127
import io.javaoperatorsdk.operator.sample.simple.TestCustomResourceController;
138
import java.util.concurrent.TimeUnit;
9+
import org.assertj.core.api.Assertions;
10+
import org.awaitility.Awaitility;
1411
import org.junit.jupiter.api.Test;
1512
import org.junit.jupiter.api.TestInstance;
1613

@@ -33,7 +30,7 @@ public void configMapGetsCreatedForTestCustomResource() {
3330
initAndCleanup(true);
3431
integrationTestSupport.teardownIfSuccess(
3532
() -> {
36-
TestCustomResource resource = testCustomResource();
33+
TestCustomResource resource = TestUtils.testCustomResource();
3734

3835
integrationTestSupport
3936
.getCrOperations()
@@ -42,7 +39,7 @@ public void configMapGetsCreatedForTestCustomResource() {
4239

4340
awaitResourcesCreatedOrUpdated();
4441
awaitStatusUpdated();
45-
assertThat(integrationTestSupport.numberOfControllerExecutions()).isEqualTo(2);
42+
Assertions.assertThat(integrationTestSupport.numberOfControllerExecutions()).isEqualTo(2);
4643
});
4744
}
4845

@@ -51,20 +48,20 @@ public void eventIsSkippedChangedOnMetadataOnlyUpdate() {
5148
initAndCleanup(false);
5249
integrationTestSupport.teardownIfSuccess(
5350
() -> {
54-
TestCustomResource resource = testCustomResource();
51+
TestCustomResource resource = TestUtils.testCustomResource();
5552

5653
integrationTestSupport
5754
.getCrOperations()
5855
.inNamespace(IntegrationTestSupport.TEST_NAMESPACE)
5956
.create(resource);
6057

6158
awaitResourcesCreatedOrUpdated();
62-
assertThat(integrationTestSupport.numberOfControllerExecutions()).isEqualTo(1);
59+
Assertions.assertThat(integrationTestSupport.numberOfControllerExecutions()).isEqualTo(1);
6360
});
6461
}
6562

6663
void awaitResourcesCreatedOrUpdated() {
67-
await("config map created")
64+
Awaitility.await("config map created")
6865
.atMost(5, TimeUnit.SECONDS)
6966
.untilAsserted(
7067
() -> {
@@ -75,8 +72,8 @@ void awaitResourcesCreatedOrUpdated() {
7572
.inNamespace(IntegrationTestSupport.TEST_NAMESPACE)
7673
.withName("test-config-map")
7774
.get();
78-
assertThat(configMap).isNotNull();
79-
assertThat(configMap.getData().get("test-key")).isEqualTo("test-value");
75+
Assertions.assertThat(configMap).isNotNull();
76+
Assertions.assertThat(configMap.getData().get("test-key")).isEqualTo("test-value");
8077
});
8178
}
8279

@@ -85,7 +82,7 @@ void awaitStatusUpdated() {
8582
}
8683

8784
void awaitStatusUpdated(int timeout) {
88-
await("cr status updated")
85+
Awaitility.await("cr status updated")
8986
.atMost(timeout, TimeUnit.SECONDS)
9087
.untilAsserted(
9188
() -> {
@@ -94,11 +91,12 @@ void awaitStatusUpdated(int timeout) {
9491
integrationTestSupport
9592
.getCrOperations()
9693
.inNamespace(IntegrationTestSupport.TEST_NAMESPACE)
97-
.withName(TEST_CUSTOM_RESOURCE_NAME)
94+
.withName(TestUtils.TEST_CUSTOM_RESOURCE_NAME)
9895
.get();
99-
assertThat(cr).isNotNull();
100-
assertThat(cr.getStatus()).isNotNull();
101-
assertThat(cr.getStatus().getConfigMapStatus()).isEqualTo("ConfigMap Ready");
96+
Assertions.assertThat(cr).isNotNull();
97+
Assertions.assertThat(cr.getStatus()).isNotNull();
98+
Assertions.assertThat(cr.getStatus().getConfigMapStatus())
99+
.isEqualTo("ConfigMap Ready");
102100
});
103101
}
104102
}

operator-framework/src/test/java/io/javaoperatorsdk/operator/EventSourceIT.java renamed to runtime-configuration/src/test/java/io/javaoperatorsdk/operator/EventSourceIT.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
package io.javaoperatorsdk.operator;
22

3-
import static io.javaoperatorsdk.operator.IntegrationTestSupport.TEST_NAMESPACE;
4-
import static io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResourceController.FINALIZER_NAME;
5-
import static io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResourceController.TIMER_DELAY;
6-
import static io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResourceController.TIMER_PERIOD;
7-
import static org.assertj.core.api.Assertions.assertThat;
8-
93
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
104
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
115
import io.fabric8.kubernetes.client.KubernetesClient;
126
import io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResource;
137
import io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResourceController;
148
import io.javaoperatorsdk.operator.sample.event.EventSourceTestCustomResourceSpec;
9+
import org.assertj.core.api.Assertions;
1510
import org.junit.jupiter.api.BeforeEach;
1611
import org.junit.jupiter.api.Test;
1712
import org.junit.jupiter.api.TestInstance;
@@ -23,7 +18,7 @@ public class EventSourceIT {
2318
private static final Logger log = LoggerFactory.getLogger(EventSourceIT.class);
2419

2520
public static final int EXPECTED_TIMER_EVENT_COUNT = 3;
26-
private IntegrationTestSupport integrationTestSupport = new IntegrationTestSupport();
21+
private final IntegrationTestSupport integrationTestSupport = new IntegrationTestSupport();
2722

2823
@BeforeEach
2924
public void initAndCleanup() {
@@ -38,11 +33,17 @@ public void receivingPeriodicEvents() {
3833
integrationTestSupport.teardownIfSuccess(
3934
() -> {
4035
EventSourceTestCustomResource resource = createTestCustomResource("1");
41-
integrationTestSupport.getCrOperations().inNamespace(TEST_NAMESPACE).create(resource);
36+
integrationTestSupport
37+
.getCrOperations()
38+
.inNamespace(IntegrationTestSupport.TEST_NAMESPACE)
39+
.create(resource);
4240

43-
Thread.sleep(TIMER_DELAY + EXPECTED_TIMER_EVENT_COUNT * TIMER_PERIOD);
41+
Thread.sleep(
42+
EventSourceTestCustomResourceController.TIMER_DELAY
43+
+ EXPECTED_TIMER_EVENT_COUNT
44+
* EventSourceTestCustomResourceController.TIMER_PERIOD);
4445

45-
assertThat(integrationTestSupport.numberOfControllerExecutions())
46+
Assertions.assertThat(integrationTestSupport.numberOfControllerExecutions())
4647
.isGreaterThanOrEqualTo(EXPECTED_TIMER_EVENT_COUNT + 1);
4748
});
4849
}
@@ -52,8 +53,8 @@ public EventSourceTestCustomResource createTestCustomResource(String id) {
5253
resource.setMetadata(
5354
new ObjectMetaBuilder()
5455
.withName("eventsource-" + id)
55-
.withNamespace(TEST_NAMESPACE)
56-
.withFinalizers(FINALIZER_NAME)
56+
.withNamespace(IntegrationTestSupport.TEST_NAMESPACE)
57+
.withFinalizers(EventSourceTestCustomResourceController.FINALIZER_NAME)
5758
.build());
5859
resource.setKind("Eventsourcesample");
5960
resource.setSpec(new EventSourceTestCustomResourceSpec());

operator-framework/src/test/java/io/javaoperatorsdk/operator/IntegrationTestSupport.java renamed to runtime-configuration/src/test/java/io/javaoperatorsdk/operator/IntegrationTestSupport.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
package io.javaoperatorsdk.operator;
22

3-
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.awaitility.Awaitility.await;
5-
63
import io.fabric8.kubernetes.api.model.Namespace;
74
import io.fabric8.kubernetes.api.model.NamespaceBuilder;
85
import io.fabric8.kubernetes.api.model.ObjectMetaBuilder;
@@ -23,12 +20,14 @@
2320
import java.io.IOException;
2421
import java.io.InputStream;
2522
import java.util.concurrent.TimeUnit;
23+
import org.assertj.core.api.Assertions;
24+
import org.awaitility.Awaitility;
2625
import org.slf4j.Logger;
2726
import org.slf4j.LoggerFactory;
2827

2928
public class IntegrationTestSupport {
3029

31-
public static final String TEST_NAMESPACE = "java-operator-sdk-int-test";
30+
public static final String TEST_NAMESPACE = io.javaoperatorsdk.operator.TestUtils.TEST_NAMESPACE;
3231
public static final String TEST_CUSTOM_RESOURCE_PREFIX = "test-custom-resource-";
3332
private static final Logger log = LoggerFactory.getLogger(IntegrationTestSupport.class);
3433
private KubernetesClient k8sClient;
@@ -89,11 +88,12 @@ public void cleanup() {
8988
// resources from previous test runs
9089
crOperations.inNamespace(TEST_NAMESPACE).delete(crOperations.list().getItems());
9190

92-
await("all CRs cleaned up")
91+
Awaitility.await("all CRs cleaned up")
9392
.atMost(60, TimeUnit.SECONDS)
9493
.untilAsserted(
9594
() -> {
96-
assertThat(crOperations.inNamespace(TEST_NAMESPACE).list().getItems()).isEmpty();
95+
Assertions.assertThat(crOperations.inNamespace(TEST_NAMESPACE).list().getItems())
96+
.isEmpty();
9797
});
9898

9999
k8sClient
@@ -102,11 +102,11 @@ public void cleanup() {
102102
.withLabel("managedBy", controller.getClass().getSimpleName())
103103
.delete();
104104

105-
await("all config maps cleaned up")
105+
Awaitility.await("all config maps cleaned up")
106106
.atMost(60, TimeUnit.SECONDS)
107107
.untilAsserted(
108108
() -> {
109-
assertThat(
109+
Assertions.assertThat(
110110
k8sClient
111111
.configMaps()
112112
.inNamespace(TEST_NAMESPACE)
@@ -137,7 +137,7 @@ public void teardownIfSuccess(TestRun test) {
137137
if (namespace.getStatus().getPhase().equals("Active")) {
138138
k8sClient.namespaces().withName(TEST_NAMESPACE).delete();
139139
}
140-
await("namespace deleted")
140+
Awaitility.await("namespace deleted")
141141
.atMost(45, TimeUnit.SECONDS)
142142
.until(() -> k8sClient.namespaces().withName(TEST_NAMESPACE).get() == null);
143143
} catch (Exception e) {

0 commit comments

Comments
 (0)