Skip to content

Commit 2d2c38b

Browse files
committed
fix js test
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 360be15 commit 2d2c38b

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

src/main/java/io/csviri/operator/resourceglue/Utils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static Map<String, GenericKubernetesResource> getActualResourcesByNameInW
3333
var dependentSpec = glue.getSpec().getResources().stream()
3434
.filter(r -> Utils.getApiVersion(r).equals(sr.getApiVersion())
3535
&& Utils.getKind(r).equals(sr.getKind())
36-
// checking the name from annotation since it might be templated name
36+
// comparing the name from annotation since the resource name might be templated in spec
3737
// therefore "Utils.getName(relatedResourceSpec).equals(sr.getMetadata().getName())" would not
3838
// work
3939
&& r.getName()

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

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
import io.javaoperatorsdk.operator.api.reconciler.Context;
1919
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
2020

21+
import static io.csviri.operator.resourceglue.reconciler.glue.GlueReconciler.DEPENDENT_NAME_ANNOTATION_KEY;
2122
import static org.assertj.core.api.Assertions.assertThat;
2223
import static org.mockito.ArgumentMatchers.any;
2324
import static org.mockito.Mockito.mock;
2425
import static org.mockito.Mockito.when;
2526

2627
class JavaScripConditionTest {
2728

29+
public static final String DR_NAME = "secondary";
2830
Context<Glue> mockContext = mock(Context.class);
2931
DependentResource<GenericKubernetesResource, Glue> dr = mock(DependentResource.class);
3032
Glue dummyGlue = new Glue();
@@ -63,25 +65,27 @@ void injectsTargetResourceResource() {
6365
}
6466

6567
@Test
66-
void injectsSecondaryResourcesResource() {
67-
when(mockContext.getSecondaryResources(any())).thenReturn(Set.of(configMap()));
68-
when(dr.getSecondaryResource(any(), any())).thenReturn(Optional.of(configMap()));
69-
70-
Glue glue = new Glue();
71-
glue.setSpec(new ResourceGlueSpec());
72-
glue.getSpec().setResources(new ArrayList<>());
73-
var drSpec = new DependentResourceSpec();
74-
drSpec.setName("secondary");
75-
drSpec.setResource(configMap());
76-
glue.getSpec().getResources().add(drSpec);
68+
void injectsSecondaryResourcesResource() {
69+
var cm = configMap();
70+
cm.getMetadata().getAnnotations().put(DEPENDENT_NAME_ANNOTATION_KEY, DR_NAME);
71+
when(mockContext.getSecondaryResources(any())).thenReturn(Set.of(cm));
72+
when(dr.getSecondaryResource(any(), any())).thenReturn(Optional.of(cm));
73+
74+
Glue glue = new Glue();
75+
glue.setSpec(new ResourceGlueSpec());
76+
glue.getSpec().setResources(new ArrayList<>());
77+
var drSpec = new DependentResourceSpec();
78+
drSpec.setName(DR_NAME);
79+
drSpec.setResource(configMap());
80+
glue.getSpec().getResources().add(drSpec);
7781

78-
var condition = new JavaScripCondition("""
79-
secondary.data.key1 == "val1";
80-
""");
82+
var condition = new JavaScripCondition("""
83+
secondary.data.key1 == "val1";
84+
""");
8185

82-
var res = condition.isMet(dr, glue, mockContext);
83-
assertThat(res).isTrue();
84-
}
86+
var res = condition.isMet(dr, glue, mockContext);
87+
assertThat(res).isTrue();
88+
}
8589

8690
private GenericKubernetesResource configMap() {
8791
try (InputStream is = JavaScripConditionTest.class.getResourceAsStream("/ConfigMap.yaml")) {

0 commit comments

Comments
 (0)