Skip to content

Commit de9225c

Browse files
committed
improve: remove owner refernce check (#2838)
this was added to fabric8 client meanwhile Signed-off-by: Attila Mészáros <[email protected]>
1 parent 7675054 commit de9225c

File tree

1 file changed

+38
-23
lines changed

1 file changed

+38
-23
lines changed

operator-framework-core/src/test/java/io/javaoperatorsdk/operator/ReconcilerUtilsTest.java

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -115,29 +115,6 @@ void setsSpecCustomResourceWithReflection() {
115115
assertThat(tomcat.getSpec().getReplicas()).isEqualTo(1);
116116
}
117117

118-
@Test
119-
void setsStatusWithReflection() {
120-
Deployment deployment = new Deployment();
121-
DeploymentStatus status = new DeploymentStatus();
122-
status.setReplicas(2);
123-
124-
ReconcilerUtils.setStatus(deployment, status);
125-
126-
assertThat(deployment.getStatus().getReplicas()).isEqualTo(2);
127-
}
128-
129-
@Test
130-
void getsStatusWithReflection() {
131-
Deployment deployment = new Deployment();
132-
DeploymentStatus status = new DeploymentStatus();
133-
status.setReplicas(2);
134-
deployment.setStatus(status);
135-
136-
var res = ReconcilerUtils.getStatus(deployment);
137-
138-
assertThat(((DeploymentStatus) res).getReplicas()).isEqualTo(2);
139-
}
140-
141118
@Test
142119
void loadYamlAsBuilder() {
143120
DeploymentBuilder builder =
@@ -176,6 +153,44 @@ void handleKubernetesExceptionShouldThrowMissingCRDExceptionWhenAppropriate() {
176153
HasMetadata.getFullResourceName(Tomcat.class)));
177154
}
178155

156+
@Test
157+
void checksIfOwnerReferenceCanBeAdded() {
158+
assertThrows(
159+
OperatorException.class,
160+
() ->
161+
ReconcilerUtils.checkIfCanAddOwnerReference(
162+
namespacedResource(), namespacedResourceFromOtherNamespace()));
163+
164+
assertThrows(
165+
OperatorException.class,
166+
() ->
167+
ReconcilerUtils.checkIfCanAddOwnerReference(
168+
namespacedResource(), clusterScopedResource()));
169+
170+
assertDoesNotThrow(
171+
() -> {
172+
ReconcilerUtils.checkIfCanAddOwnerReference(
173+
clusterScopedResource(), clusterScopedResource());
174+
ReconcilerUtils.checkIfCanAddOwnerReference(namespacedResource(), namespacedResource());
175+
});
176+
}
177+
178+
private ClusterRole clusterScopedResource() {
179+
return new ClusterRoleBuilder().withMetadata(new ObjectMetaBuilder().build()).build();
180+
}
181+
182+
private ConfigMap namespacedResource() {
183+
return new ConfigMapBuilder()
184+
.withMetadata(new ObjectMetaBuilder().withNamespace("testns1").build())
185+
.build();
186+
}
187+
188+
private ConfigMap namespacedResourceFromOtherNamespace() {
189+
return new ConfigMapBuilder()
190+
.withMetadata(new ObjectMetaBuilder().withNamespace("testns2").build())
191+
.build();
192+
}
193+
179194
@Group("tomcatoperator.io")
180195
@Version("v1")
181196
@ShortNames("tc")

0 commit comments

Comments
 (0)