Example #1
0
        public async Task OnIncomingEvent_EventsAreDispatched(WatchEventType eventType)
        {
            // Arrange
            var resource   = CreateCustomResource(ns: "default");
            var controller = new TestableController(_client, _loggerFactory);

            _operator.AddController(controller);
            var task = _operator.StartAsync();

            // Act
            _operator.SimulateEvent(controller, eventType, resource);

            // Assert
            _operator.Stop(); await task;
            VerifyAddOrModifyIsCalledWith(controller, resource);
        }
Example #2
0
        public async Task OnIncomingEvent_EventsAreDispatchedAndIgnored(WatchEventType eventType)
        {
            // Arrange
            var resource   = CreateCustomResource(ns: "namespace1");
            var controller = new TestableController(_client);

            _operator.AddController(controller, "namespace1");
            var task = _operator.StartAsync();

            // Act
            _operator.SimulateEvent(controller, eventType, resource);

            // Assert
            _operator.Stop(); await task;
            VerifyAddOrModifyIsNotCalled(controller);
            VerifyDeleteIsNotCalled(controller);
        }
Example #3
0
        public async Task OnIncomingEvent_EventsAreDispatchedToAssociatedControllers(WatchEventType eventType, string allNamespaceVariant)
        {
            // Arrange
            var resource1   = CreateCustomResource(ns: "namespace1");
            var resource2   = CreateCustomResource(ns: "namespace2");
            var controller1 = new TestableController(_client);
            var controller2 = new TestableController(_client);

            _operator.AddController(controller1, allNamespaceVariant);
            _operator.AddController(controller2, "namespace2");
            var task = _operator.StartAsync();

            // Act
            _operator.SimulateEvent(controller1, eventType, resource1);
            _operator.SimulateEvent(controller2, eventType, resource2);

            // Assert
            _operator.Stop(); await task;
            VerifyAddOrModifyIsCalledWith(controller1, resource1);
            VerifyAddOrModifyIsCalledWith(controller2, resource2);
        }
        public async Task ProcessEventAsync_DuplicateGenerationsAreProcessedIfForcedByConfiguration(WatchEventType eventType)
        {
            // Arrange
            var controller = new TestableController(new OperatorConfiguration()
            {
                DiscardDuplicateSpecGenerations = false
            }, _client);
            var resource_v1 = CreateCustomResource(generation: 1);
            var resource_v2 = CreateCustomResource(generation: 2);

            // Act
            await controller.ProcessEventAsync(new CustomResourceEvent(eventType, resource_v1), DUMMY_TOKEN);

            await controller.ProcessEventAsync(new CustomResourceEvent(eventType, resource_v1), DUMMY_TOKEN); // duplicate generation

            await controller.ProcessEventAsync(new CustomResourceEvent(eventType, resource_v2), DUMMY_TOKEN);

            // Assert
            VerifyAddOrModifyIsCalledWith(controller, resource_v1, resource_v1, resource_v2);
            VerifyDeleteIsNotCalled(controller);
            VerifyNoOtherApiIsCalled();
        }
Example #5
0
 protected void VerifyCompletedEvents(TestableController controller, params (TestableCustomResource resource, bool deleteEvent)[] inputs) => Assert.Equal(inputs, controller.CompletedEvents);
 public ControllerTests()
 {
     _controller = new TestableController(OperatorConfiguration.Default, _client);
     _controller.RetryPolicy.InitialDelay = 1;
 }