|
3 | 3 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
5 | 5 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
| 6 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 7 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
6 | 8 |
|
| 9 | +import ch.qos.logback.classic.Logger; |
| 10 | +import ch.qos.logback.classic.spi.ILoggingEvent; |
| 11 | +import ch.qos.logback.core.read.ListAppender; |
7 | 12 | import io.fabric8.kubernetes.client.CustomResource;
|
8 | 13 | import io.fabric8.kubernetes.model.annotation.Group;
|
9 | 14 | import io.fabric8.kubernetes.model.annotation.Version;
|
|
12 | 17 | import io.javaoperatorsdk.operator.api.Controller;
|
13 | 18 | import io.javaoperatorsdk.operator.api.ResourceController;
|
14 | 19 | import io.javaoperatorsdk.operator.api.UpdateControl;
|
| 20 | +import io.javaoperatorsdk.operator.api.config.AbstractConfigurationService; |
15 | 21 | import org.junit.jupiter.api.Test;
|
| 22 | +import org.slf4j.LoggerFactory; |
16 | 23 |
|
17 | 24 | public class DefaultConfigurationServiceTest {
|
18 | 25 |
|
19 | 26 | public static final String CUSTOM_FINALIZER_NAME = "a.custom/finalizer";
|
20 | 27 |
|
| 28 | + @Test |
| 29 | + void attemptingToRetrieveAnUnknownControllerShouldLogWarning() { |
| 30 | + final var logger = (Logger) LoggerFactory.getLogger(AbstractConfigurationService.LOGGER_NAME); |
| 31 | + final var appender = new ListAppender<ILoggingEvent>(); |
| 32 | + logger.addAppender(appender); |
| 33 | + appender.start(); |
| 34 | + try { |
| 35 | + final var config = |
| 36 | + DefaultConfigurationService.instance() |
| 37 | + .getConfigurationFor(new NotAutomaticallyCreated(), false); |
| 38 | + assertNull(config); |
| 39 | + assertEquals(1, appender.list.size()); |
| 40 | + assertTrue( |
| 41 | + appender.list.stream() |
| 42 | + .allMatch( |
| 43 | + e -> { |
| 44 | + final var message = e.getFormattedMessage(); |
| 45 | + return message.contains(NotAutomaticallyCreated.NAME) |
| 46 | + && message.contains("not found"); |
| 47 | + })); |
| 48 | + } finally { |
| 49 | + logger.detachAndStopAllAppenders(); |
| 50 | + } |
| 51 | + } |
| 52 | + |
21 | 53 | @Test
|
22 | 54 | public void returnsValuesFromControllerAnnotationFinalizer() {
|
23 | 55 | final var controller = new TestCustomResourceController();
|
@@ -65,6 +97,18 @@ public UpdateControl<TestCustomFinalizerController.InnerCustomResource> createOr
|
65 | 97 | }
|
66 | 98 | }
|
67 | 99 |
|
| 100 | + @Controller(name = NotAutomaticallyCreated.NAME) |
| 101 | + static class NotAutomaticallyCreated implements ResourceController<TestCustomResource> { |
| 102 | + |
| 103 | + public static final String NAME = "should-be-logged"; |
| 104 | + |
| 105 | + @Override |
| 106 | + public UpdateControl<TestCustomResource> createOrUpdateResource( |
| 107 | + TestCustomResource resource, Context<TestCustomResource> context) { |
| 108 | + return null; |
| 109 | + } |
| 110 | + } |
| 111 | + |
68 | 112 | @Controller(generationAwareEventProcessing = false, name = "test")
|
69 | 113 | static class TestCustomResourceController implements ResourceController<TestCustomResource> {
|
70 | 114 |
|
|
0 commit comments