|
| 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.javaoperatorsdk.operator.junit.LocallyRunOperatorExtension; |
| 9 | +import io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiableDependentPartCustomResource; |
| 10 | +import io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiableDependentPartReconciler; |
| 11 | +import io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiableDependentPartSpec; |
| 12 | + |
| 13 | +import static io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiablePartConfigMapDependent.ACTUAL_DATA_KEY; |
| 14 | +import static io.javaoperatorsdk.operator.sample.unmodifiabledependentpart.UnmodifiablePartConfigMapDependent.UNMODIFIABLE_INITIAL_DATA_KEY; |
| 15 | +import static org.assertj.core.api.Assertions.assertThat; |
| 16 | +import static org.awaitility.Awaitility.await; |
| 17 | + |
| 18 | +public class UnmodifiableDependentPartIT { |
| 19 | + |
| 20 | + public static final String TEST_RESOURCE_NAME = "test1"; |
| 21 | + public static final String INITIAL_DATA = "initialData"; |
| 22 | + public static final String UPDATED_DATA = "updatedData"; |
| 23 | + |
| 24 | + @RegisterExtension |
| 25 | + LocallyRunOperatorExtension operator = |
| 26 | + LocallyRunOperatorExtension.builder() |
| 27 | + .withReconciler(UnmodifiableDependentPartReconciler.class) |
| 28 | + .build(); |
| 29 | + |
| 30 | + @Test |
| 31 | + void partConfigMapDataUnmodifiable() { |
| 32 | + var resource = operator.create(testResource()); |
| 33 | + |
| 34 | + await().untilAsserted(() -> { |
| 35 | + var cm = operator.get(ConfigMap.class, TEST_RESOURCE_NAME); |
| 36 | + assertThat(cm).isNotNull(); |
| 37 | + assertThat(cm.getData()).containsEntry(UNMODIFIABLE_INITIAL_DATA_KEY, INITIAL_DATA); |
| 38 | + assertThat(cm.getData()).containsEntry(ACTUAL_DATA_KEY, INITIAL_DATA); |
| 39 | + }); |
| 40 | + |
| 41 | + resource.getSpec().setData(UPDATED_DATA); |
| 42 | + operator.replace(resource); |
| 43 | + |
| 44 | + await().untilAsserted(() -> { |
| 45 | + var cm = operator.get(ConfigMap.class, TEST_RESOURCE_NAME); |
| 46 | + assertThat(cm).isNotNull(); |
| 47 | + assertThat(cm.getData()).containsEntry(UNMODIFIABLE_INITIAL_DATA_KEY, INITIAL_DATA); |
| 48 | + assertThat(cm.getData()).containsEntry(ACTUAL_DATA_KEY, UPDATED_DATA); |
| 49 | + }); |
| 50 | + } |
| 51 | + |
| 52 | + |
| 53 | + UnmodifiableDependentPartCustomResource testResource() { |
| 54 | + var res = new UnmodifiableDependentPartCustomResource(); |
| 55 | + res.setMetadata(new ObjectMetaBuilder() |
| 56 | + .withName(TEST_RESOURCE_NAME) |
| 57 | + .build()); |
| 58 | + res.setSpec(new UnmodifiableDependentPartSpec()); |
| 59 | + res.getSpec().setData(INITIAL_DATA); |
| 60 | + return res; |
| 61 | + } |
| 62 | + |
| 63 | +} |
0 commit comments