Untitled

mail@pastecode.io avatar
unknown
plain_text
24 days ago
1.6 kB
3
Indexable
Never
public void testLoggingHappyCase_verifyRolePassedToSSM_whenSlr() {
        SsmClientWrapper ssmClientWrapper = new SsmClientWrapper(ssmClient);

        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(ssmClientWrapperSpy.getInstanceToSsmCapabilityMap(Collections.singletonList("GoodInstance")))
                .thenReturn(instanceToSsmCapabilityMap);

        loggingUpdateHelper.performLoggingUpdate(cp, ssmClientWrapperSpy, 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"));
    }
Leave a Comment