Untitled

 avatar
unknown
plain_text
10 months ago
2.4 kB
6
Indexable
private void setupSSMClientBuilder() {
        // when(ssmClientWrapper.SendCommandToInstances()).thenReturn(cmdBuilder);
        when(ssmClientWrapper.SendCommandToInstances()).thenCallRealMethod();

        cmdBuilder.build();
        
        when(cmdBuilder.parameters(anyMap())).thenReturn(cmdBuilder);
        when(cmdBuilder.instanceIds(instanceIdsCaptor.capture())).thenReturn(cmdBuilder);
        when(cmdBuilder.deliveryTimeoutInSeconds(60)).thenReturn(cmdBuilder);
        when(cmdBuilder.outputS3BucketName("SSMLogsBucket")).thenReturn(cmdBuilder);
        when(cmdBuilder.documentName("documentName")).thenReturn(cmdBuilder);
        when(cmdBuilder.outputS3KeyPrefix(any())).thenReturn(cmdBuilder);
        when(cmdBuilder.build()).thenReturn("commandID");
    }

   public void testLoggingHappyCase_verifyRolePassedToSSM_whenSlr() {
        // SsmClientWrapper ssmClientWrapper = new SsmClientWrapper(ssmClient);
        // SsmClientWrapper ssmClientWrapperSpy = spy(ssmClientWrapper);

        

        // setupSSMClientBuilder();
        setupSSMClientCommand("Success");
        ClusterProperties cp = buildClusterProperties();
        cp.setControlPlaneRoleArn(SLR_ARN);
        when(asgClient.listInstances(any())).thenReturn(
                Arrays.asList(new Instance().withInstanceId("GoodInstance").withLifecycleState(LifecycleState.InService),
                        new Instance().withInstanceId("BadInstance").withLifecycleState(LifecycleState.Terminating)));

        Map<String, String> instanceToSsmCapabilityMap = new HashMap<>();
        instanceToSsmCapabilityMap.put("GoodInstance", "shell");
        when(ssmClientWrapper.getInstanceToSsmCapabilityMap(Collections.singletonList("GoodInstance")))
                .thenReturn(instanceToSsmCapabilityMap);
        

        loggingUpdateHelper.performLoggingUpdate(cp, ssmClientWrapper, asgClient,
                "documentName", "SSMLogsBucket");

        verify(ssmClient, times(1)).sendCommand(sendCommandRequestCaptor.capture());
        assertTrue(sendCommandRequestCaptor.getValue().getParameters().containsKey("Logging"));
        final String loggingSsmDocContent = sendCommandRequestCaptor.getValue().getParameters().get("Logging").get(0);
        String loggingConfig = new String(Base64.getDecoder().decode(loggingSsmDocContent));
        assertTrue(loggingConfig.contains(SLR_ARN));
        assertTrue(loggingConfig.contains("role_arn"));
    }
Editor is loading...
Leave a Comment