|
18 | 18 | import io.javaoperatorsdk.operator.api.reconciler.Context;
|
19 | 19 | import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
|
20 | 20 |
|
| 21 | +import static io.csviri.operator.resourceglue.reconciler.glue.GlueReconciler.DEPENDENT_NAME_ANNOTATION_KEY; |
21 | 22 | import static org.assertj.core.api.Assertions.assertThat;
|
22 | 23 | import static org.mockito.ArgumentMatchers.any;
|
23 | 24 | import static org.mockito.Mockito.mock;
|
24 | 25 | import static org.mockito.Mockito.when;
|
25 | 26 |
|
26 | 27 | class JavaScripConditionTest {
|
27 | 28 |
|
| 29 | + public static final String DR_NAME = "secondary"; |
28 | 30 | Context<Glue> mockContext = mock(Context.class);
|
29 | 31 | DependentResource<GenericKubernetesResource, Glue> dr = mock(DependentResource.class);
|
30 | 32 | Glue dummyGlue = new Glue();
|
@@ -63,25 +65,27 @@ void injectsTargetResourceResource() {
|
63 | 65 | }
|
64 | 66 |
|
65 | 67 | @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); |
77 | 81 |
|
78 |
| - var condition = new JavaScripCondition(""" |
79 |
| - secondary.data.key1 == "val1"; |
80 |
| - """); |
| 82 | + var condition = new JavaScripCondition(""" |
| 83 | + secondary.data.key1 == "val1"; |
| 84 | + """); |
81 | 85 |
|
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 | + } |
85 | 89 |
|
86 | 90 | private GenericKubernetesResource configMap() {
|
87 | 91 | try (InputStream is = JavaScripConditionTest.class.getResourceAsStream("/ConfigMap.yaml")) {
|
|
0 commit comments