diff options
author | FrancescoFioraEst <francesco.fiora@est.tech> | 2022-09-13 15:54:10 +0100 |
---|---|---|
committer | FrancescoFioraEst <francesco.fiora@est.tech> | 2022-09-20 10:00:49 +0100 |
commit | a368937411e8767bc19f50a7968567fb68a6dfeb (patch) | |
tree | 9c826430c8ecf6e0843aca26341b7af68cc4416e /participant/participant-impl/participant-impl-kubernetes/src/test | |
parent | 18a13eaef5fc51556b0985c61e271dfc5a3a4a29 (diff) |
Fix PodStatus Validator failing in K8sParticipant
Fix PodStatus Validator failing in K8sParticipant using service template
for Test and Verification of ACM State Management.
Issue-ID: POLICY-4355
Change-Id: I63f8ed2c4991422dd43749151387ff54ba7d6071
Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'participant/participant-impl/participant-impl-kubernetes/src/test')
2 files changed, 30 insertions, 9 deletions
diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java index fbddf8b28..962744db7 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/java/org/onap/policy/clamp/acm/participant/kubernetes/helm/PodStatusValidatorTest.java @@ -35,7 +35,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; import org.mockito.MockedStatic; import org.onap.policy.clamp.acm.participant.kubernetes.exception.ServiceException; import org.onap.policy.clamp.acm.participant.kubernetes.handler.AutomationCompositionElementHandler; @@ -51,20 +50,16 @@ class PodStatusValidatorTest { private static final Coder CODER = new StandardCoder(); private static final String CHART_INFO_YAML = "src/test/resources/ChartList.json"; + private static int TIMEOUT = 2; + private static int STATUS_CHECK_INTERVAL = 1; private static List<ChartInfo> charts; - @InjectMocks - private static PodStatusValidator podStatusValidator; - private static MockedStatic<HelmClient> mockedClient; @BeforeAll static void init() throws CoderException { charts = CODER.decode(new File(CHART_INFO_YAML), ChartList.class).getCharts(); mockedClient = mockStatic(HelmClient.class); - int timeout = 60; - int statusCheckInterval = 30; - podStatusValidator = new PodStatusValidator(charts.get(0), timeout, statusCheckInterval); } @AfterEach @@ -77,12 +72,12 @@ class PodStatusValidatorTest { mockedClient.close(); } - @Test void test_RunningPodState() { String runningPod = "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\r\nHelloWorld-54777df9f8-qpzqr\t1/1\tRunning\t0\t9h"; mockedClient.when(() -> HelmClient.executeCommand(any())) .thenReturn(runningPod); + var podStatusValidator = new PodStatusValidator(charts.get(0), TIMEOUT, STATUS_CHECK_INTERVAL); assertDoesNotThrow(() -> podStatusValidator.run()); assertThat(AutomationCompositionElementHandler.getPodStatusMap()).hasSize(1); assertThat(AutomationCompositionElementHandler.getPodStatusMap()).containsKey(charts.get(0).getReleaseName()); @@ -90,15 +85,28 @@ class PodStatusValidatorTest { .containsValue(Map.of("HelloWorld-54777df9f8-qpzqr", "Running")); } - @Test void test_InvalidPodState() { String invalidPod = "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\nhellofromdocker-54777df9f8-qpzqr\t1/1\tInit\t0\t9h"; mockedClient.when(() -> HelmClient.executeCommand(any())) .thenReturn(invalidPod); + var podStatusValidator = new PodStatusValidator(charts.get(1), TIMEOUT, STATUS_CHECK_INTERVAL); assertThatThrownBy(() -> podStatusValidator.run()) .isInstanceOf(ServiceException.class).hasMessage("Error verifying the status of the pod. Exiting"); assertThat(AutomationCompositionElementHandler.getPodStatusMap()).isEmpty(); } + // Use case scenario: Hard coded pod name + @Test + void test_RunningPodStateWhitPodName() { + String runningPod = "NAME\tREADY\tSTATUS\tRESTARTS\tAGE\r\nhelloallworld-54777df9f8-qpzqr\t1/1\tRunning\t0\t9h"; + mockedClient.when(() -> HelmClient.executeCommand(any())) + .thenReturn(runningPod); + var podStatusValidator = new PodStatusValidator(charts.get(2), TIMEOUT, STATUS_CHECK_INTERVAL); + assertDoesNotThrow(() -> podStatusValidator.run()); + assertThat(AutomationCompositionElementHandler.getPodStatusMap()).hasSize(1); + assertThat(AutomationCompositionElementHandler.getPodStatusMap()).containsKey(charts.get(2).getReleaseName()); + assertThat(AutomationCompositionElementHandler.getPodStatusMap()) + .containsValue(Map.of("helloallworld-54777df9f8-qpzqr", "Running")); + } } diff --git a/participant/participant-impl/participant-impl-kubernetes/src/test/resources/ChartList.json b/participant/participant-impl/participant-impl-kubernetes/src/test/resources/ChartList.json index d4cd5de47..f58049640 100644 --- a/participant/participant-impl/participant-impl-kubernetes/src/test/resources/ChartList.json +++ b/participant/participant-impl/participant-impl-kubernetes/src/test/resources/ChartList.json @@ -19,6 +19,19 @@ }, "namespace" : "onap", "releaseName" : "nginxapp" + }, + { + "chartId" : { + "name" : "HelloWorld", + "version" : "1.2" + }, + "namespace" : "onap", + "repository" : { + "repoName": "chartMuseum", + "address" : "https://localhost:8080" + }, + "releaseName" : "helloworld", + "podName" : "helloallworld" } ] } |