|
| 1 | +package io.javaoperatorsdk.operator; |
| 2 | + |
| 3 | +import org.junit.jupiter.api.Test; |
| 4 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 5 | + |
| 6 | +import io.fabric8.kubernetes.api.model.ConfigMap; |
| 7 | +import io.fabric8.kubernetes.api.model.ObjectMetaBuilder; |
| 8 | +import io.fabric8.kubernetes.api.model.Secret; |
| 9 | +import io.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; |
| 10 | +import io.javaoperatorsdk.operator.sample.multipledependentwithactivation.*; |
| 11 | + |
| 12 | +import static org.assertj.core.api.Assertions.assertThat; |
| 13 | +import static org.awaitility.Awaitility.await; |
| 14 | + |
| 15 | +public class MultipleDependentWithActivationIT { |
| 16 | + |
| 17 | + public static final String INITIAL_VALUE = "initial_value"; |
| 18 | + public static final String CHANGED_VALUE = "changed_value"; |
| 19 | + public static final String TEST_RESOURCE_NAME = "test1"; |
| 20 | + |
| 21 | + @RegisterExtension |
| 22 | + LocallyRunOperatorExtension extension = |
| 23 | + LocallyRunOperatorExtension.builder() |
| 24 | + .withReconciler(new MultipleDependentActivationReconciler()) |
| 25 | + .build(); |
| 26 | + |
| 27 | + @Test |
| 28 | + void bothDependentsWithActivationAreHandled() { |
| 29 | + var resource = extension.create(testResource()); |
| 30 | + |
| 31 | + await().untilAsserted(() -> { |
| 32 | + var cm1 = |
| 33 | + extension.get(ConfigMap.class, TEST_RESOURCE_NAME + ConfigMapDependentResource1.SUFFIX); |
| 34 | + var cm2 = |
| 35 | + extension.get(ConfigMap.class, TEST_RESOURCE_NAME + ConfigMapDependentResource2.SUFFIX); |
| 36 | + var secret = extension.get(Secret.class, TEST_RESOURCE_NAME); |
| 37 | + assertThat(secret).isNotNull(); |
| 38 | + assertThat(cm1).isNull(); |
| 39 | + assertThat(cm2).isNull(); |
| 40 | + }); |
| 41 | + |
| 42 | + ActivationCondition.MET = true; |
| 43 | + resource.getSpec().setValue(CHANGED_VALUE); |
| 44 | + extension.replace(resource); |
| 45 | + |
| 46 | + await().untilAsserted(() -> { |
| 47 | + var cm1 = |
| 48 | + extension.get(ConfigMap.class, TEST_RESOURCE_NAME + ConfigMapDependentResource1.SUFFIX); |
| 49 | + var cm2 = |
| 50 | + extension.get(ConfigMap.class, TEST_RESOURCE_NAME + ConfigMapDependentResource2.SUFFIX); |
| 51 | + var secret = extension.get(Secret.class, TEST_RESOURCE_NAME); |
| 52 | + |
| 53 | + assertThat(secret).isNotNull(); |
| 54 | + assertThat(cm1).isNotNull(); |
| 55 | + assertThat(cm2).isNotNull(); |
| 56 | + assertThat(cm1.getData()).containsEntry(ConfigMapDependentResource1.DATA_KEY, |
| 57 | + CHANGED_VALUE + ConfigMapDependentResource1.SUFFIX); |
| 58 | + assertThat(cm2.getData()).containsEntry(ConfigMapDependentResource2.DATA_KEY, |
| 59 | + CHANGED_VALUE + ConfigMapDependentResource2.SUFFIX); |
| 60 | + }); |
| 61 | + |
| 62 | + } |
| 63 | + |
| 64 | + MultipleDependentActivationCustomResource testResource() { |
| 65 | + var res = new MultipleDependentActivationCustomResource(); |
| 66 | + res.setMetadata(new ObjectMetaBuilder() |
| 67 | + .withName(TEST_RESOURCE_NAME) |
| 68 | + .build()); |
| 69 | + res.setSpec(new MultipleDependentActivationSpec()); |
| 70 | + res.getSpec().setValue(INITIAL_VALUE); |
| 71 | + |
| 72 | + return res; |
| 73 | + } |
| 74 | + |
| 75 | + |
| 76 | +} |
0 commit comments