Пример #1
0
        public async Task HandleAsync_Will_Act_Idempotent_When_Role_Already_Exist()
        {
            // Arrange
            var roleName                 = "new-role-to-be-created";
            var configMapServiceSpy      = new ConfigMapServiceSpy();
            var namespaceRepositorySpy   = new NamespaceRepositorySpy();
            var errornousRoleRepository  = new ErrornousRoleRepository(new RoleAlreadyExistException($"Role already exist", roleName));
            var roleBindingRepositorySpy = new RoleBindingRepositorySpy();
            var k8sAppService            = new K8sApplicationServiceSpy();
            var logger = new LoggerFactory().CreateLogger <ContextAccountCreatedDomainEventHandler>();
            var sut    = new ContextAccountCreatedDomainEventHandler(
                configMapServiceSpy,
                namespaceRepositorySpy,
                errornousRoleRepository,
                roleBindingRepositorySpy,
                k8sAppService,
                logger
                );

            var @event = new ContextAccountCreatedDomainEventBuilder().Build();

            // Act
            await sut.HandleAsync(@event);

            // Assert
            var namespaceName = configMapServiceSpy.Roles.Single().Key;

            Assert.Equal(namespaceName, roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item1);
            Assert.Equal(roleName, roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item2);
            Assert.Equal(namespaceName, roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item3);
            Assert.Equal(namespaceName, k8sAppService.Payload_Namespace);
            Assert.Equal(@event.Payload.ContextId, k8sAppService.Payload_ContextId);
            Assert.Equal(@event.Payload.CapabilityId, k8sAppService.Payload_CapabilityId);
        }
Пример #2
0
        public async Task HandleAsync_Will_Act_Idempotent_When_Namespace_Already_Exist()
        {
            // Arrange
            var configMapServiceSpy      = new ConfigMapServiceSpy();
            var namespaceRepositorySpy   = new ErrornousNamespaceRepository(new NamespaceAlreadyExistException("Namespace already exist"));
            var roleRepositorySpy        = new RoleRepositorySpy();
            var roleBindingRepositorySpy = new RoleBindingRepositorySpy();
            var k8sAppService            = new K8sApplicationServiceSpy();
            var logger = new LoggerFactory().CreateLogger <ContextAccountCreatedDomainEventHandler>();
            var sut    = new ContextAccountCreatedDomainEventHandler(
                configMapServiceSpy,
                namespaceRepositorySpy,
                roleRepositorySpy,
                roleBindingRepositorySpy,
                k8sAppService,
                logger
                );

            var @event = new ContextAccountCreatedDomainEventBuilder().Build();

            // Act
            await sut.HandleAsync(@event);

            // Assert
            Assert.NotEmpty(configMapServiceSpy.Roles.Single().Value);

            var namespaceName = configMapServiceSpy.Roles.Single().Key;

            //Assert.Equal(@event.Payload.RoleArn, @namespace.Annotations["iam.amazonaws.com/permitted"]);
            //
            Assert.Equal(namespaceName, roleRepositorySpy.Namespaces.Single());
            Assert.Equal(namespaceName, roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item1);
            Assert.Equal(namespaceName + "-full-access-role",
                         roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item2);
            Assert.Equal(namespaceName, roleBindingRepositorySpy.NamespaceRoleToGroupBindings.Single().Item3);
            Assert.Equal(namespaceName, k8sAppService.Payload_Namespace);
            Assert.Equal(@event.Payload.ContextId, k8sAppService.Payload_ContextId);
            Assert.Equal(@event.Payload.CapabilityId, k8sAppService.Payload_CapabilityId);
        }
Пример #3
0
        public async Task HandleAsync_Will_Act_Idempotent_When_RoleBinding_Already_Exist()
        {
            // Arrange
            var configMapServiceSpy      = new ConfigMapServiceSpy();
            var namespaceRepositorySpy   = new NamespaceRepositorySpy();
            var roleRepositorySpy        = new RoleRepositorySpy();
            var roleBindingRepositorySpy = new ErrornousRoleBindingRepository(new RoleBindingAlreadyExistInNamespaceException("RoleBinding exists", "", ""));
            var k8sAppService            = new K8sApplicationServiceSpy();
            var logger = new LoggerFactory().CreateLogger <ContextAccountCreatedDomainEventHandler>();
            var sut    = new ContextAccountCreatedDomainEventHandler(
                configMapServiceSpy,
                namespaceRepositorySpy,
                roleRepositorySpy,
                roleBindingRepositorySpy,
                k8sAppService,
                logger
                );

            var @event = new ContextAccountCreatedDomainEventBuilder().Build();

            // Act and Assert
            await sut.HandleAsync(@event);
        }