diff options
author | 2021-04-21 13:59:12 +0200 | |
---|---|---|
committer | 2021-05-14 14:58:14 +0000 | |
commit | e3de4c9d214983d38a7d66e89dae5d4bba170ca3 (patch) | |
tree | 9f92e5fc15d06051ffff254588bbcc1e85214d3f /openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org | |
parent | df353be353e1ec25ac2a0e64a9eb617dcbc87703 (diff) |
Integrate helm validator with SDC-BE
- Read helm validator configuration
- Add call to helm validator during Helm validation
- Add JUnit tests
- Fix display message when CNF upload is unsuccessful
- Show warning messages from validation after CNF upload
Issue-ID: SDC-3185
Signed-off-by: Joanna Jeremicz <joanna.jeremicz@nokia.com>
Change-Id: If197d557e6ddef4a07bef986d7cf133aedcb2cc5
Signed-off-by: Piotr Marcinkiewicz <piotr.marcinkiewicz@nokia.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org')
4 files changed, 444 insertions, 5 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/util/HelmValidatorConfigReaderTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/util/HelmValidatorConfigReaderTest.java new file mode 100644 index 0000000000..ba4728f8d5 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/util/HelmValidatorConfigReaderTest.java @@ -0,0 +1,113 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nokia + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.validation.impl.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.when; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.onap.config.api.Configuration; +import org.openecomp.sdc.validation.type.helmvalidator.HelmValidatorConfig; + +@ExtendWith(MockitoExtension.class) +class HelmValidatorConfigReaderTest { + + private final static String CONFIG_NAMESPACE = "helmvalidator"; + @Mock + private Configuration configuration; + + @ParameterizedTest + @ValueSource(strings = {"v3", "3.4.5"}) + void shouldReadVersionFromConfig(String helmVersion) { + //given + when(configuration.getAsString(CONFIG_NAMESPACE, "hValidatorVersion")).thenReturn(helmVersion); + HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration); + //when + HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig(); + //then + assertEquals(helmVersion, helmValidatorConfig.getVersion()); + } + + @ParameterizedTest + @ValueSource(strings = {"http://localhost:3211", "https://test-abc"}) + void shouldReadValidatorUrlFromConfig(String validatorUrl) { + //given + when(configuration.getAsString(CONFIG_NAMESPACE, "hValidatorUrl")).thenReturn(validatorUrl); + HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration); + //when + HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig(); + //then + assertEquals(validatorUrl, helmValidatorConfig.getValidatorUrl()); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void shouldReadEnabledValueFromConfig(boolean isEnabled) { + //given + when(configuration.getAsBooleanValue(CONFIG_NAMESPACE, "hValidatorEnabled")).thenReturn(isEnabled); + HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration); + //when + HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig(); + //then + Assertions.assertEquals(isEnabled, helmValidatorConfig.isEnabled()); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void shouldReadDeployableValueFromConfig(boolean isDeployable) { + //given + when(configuration.getAsBooleanValue(CONFIG_NAMESPACE, "hValidatorDeployable")).thenReturn(isDeployable); + HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration); + //when + HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig(); + //then + Assertions.assertEquals(isDeployable, helmValidatorConfig.isDeployable()); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void shouldReadLintableValueFromConfig(boolean isLintable) { + //given + when(configuration.getAsBooleanValue(CONFIG_NAMESPACE, "hValidatorLintable")).thenReturn(isLintable); + HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration); + //when + HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig(); + //then + Assertions.assertEquals(isLintable, helmValidatorConfig.isLintable()); + } + + @ParameterizedTest + @ValueSource(booleans = {true, false}) + void shouldReadStrictLintableValueFromConfig(boolean isStrictLintable) { + //given + when(configuration.getAsBooleanValue(CONFIG_NAMESPACE, "hValidatorStrictLintable")) + .thenReturn(isStrictLintable); + HelmValidatorConfigReader helmValidatorConfigReader = new HelmValidatorConfigReader(configuration); + //when + HelmValidatorConfig helmValidatorConfig = helmValidatorConfigReader.getHelmValidatorConfig(); + //then + Assertions.assertEquals(isStrictLintable, helmValidatorConfig.isStrictLintable()); + } +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/util/HelmValidatorHttpClientTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/util/HelmValidatorHttpClientTest.java new file mode 100644 index 0000000000..be1c1a81e2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/util/HelmValidatorHttpClientTest.java @@ -0,0 +1,185 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nokia + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.validation.impl.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.text.MessageFormat; +import java.util.stream.Collectors; +import org.apache.http.HttpEntity; +import org.apache.http.protocol.HTTP; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; +import org.junit.jupiter.params.provider.ValueSource; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.openecomp.sdc.common.http.client.api.HttpExecuteException; +import org.openecomp.sdc.common.http.client.api.HttpRequestHandler; +import org.openecomp.sdc.common.http.client.api.HttpResponse; +import org.openecomp.sdc.validation.type.helmvalidator.HelmValidatorConfig; + +@ExtendWith(MockitoExtension.class) +class HelmValidatorHttpClientTest { + + private static final String EXAMPLE_RESPONSE = "{\"renderErrors\":[],\"lintWarning\":[\"[WARNING] warning description\"],\"lintError\":[],\"versionUsed\":\"3.5.2\",\"valid\":false,\"deployable\":true}"; + private static final String TEST_CHART_FILE_NAME = "testchart"; + private static final String HTTP_ENTITY_PATTERN = + "Content-Disposition: form-data; name=\"file\"; filename=\"{0}\" {1} " + + "Content-Disposition: form-data; name=\"isLinted\" {2} " + + "Content-Disposition: form-data; name=\"isStrictLinted\" {3} " + + "Content-Disposition: form-data; name=\"versionDesired\" {4}"; + private static final String HTTPS_TEST_URL = "https://test-url"; + private static final String TEST_VERSION = "3.5.6"; + @Mock + private HttpRequestHandler httpRequestHandler; + @Mock + private HelmValidatorConfig helmValidatorConfig; + @InjectMocks + private HelmValidatorHttpClient client; + @Captor + private ArgumentCaptor<HttpEntity> httpEntityCaptor; + @TempDir + static Path tempDir; + + @BeforeEach + void init() throws HttpExecuteException { + when(httpRequestHandler.post(any(), any(), any(), any())) + .thenReturn(new HttpResponse<>(EXAMPLE_RESPONSE, 215)); + when(helmValidatorConfig.getValidatorUrl()).thenReturn(HTTPS_TEST_URL); + when(helmValidatorConfig.getVersion()).thenReturn(TEST_VERSION); + } + + @ParameterizedTest + @ValueSource(strings = {"http://test123", "test-url:8080"}) + void shouldSendPostToValidatorUrl(String validatorUrl) throws Exception { + when(helmValidatorConfig.getValidatorUrl()).thenReturn(validatorUrl); + //given, when + var response = client.execute(TEST_CHART_FILE_NAME, "".getBytes(), helmValidatorConfig); + //then + Assertions.assertEquals(215, response.getStatusCode()); + Assertions.assertEquals(EXAMPLE_RESPONSE, response.getResponse()); + verify(httpRequestHandler).post(eq(validatorUrl), any(), any(), any()); + } + + @ParameterizedTest + @ValueSource(strings = {"3.5.4", "v3", "1.2.3"}) + void shouldPrepareRequestWithDesiredVersion(String desiredVersion) throws Exception { + //given + Path chartPath = getTestPath(TEST_CHART_FILE_NAME, ""); + when(helmValidatorConfig.getVersion()).thenReturn(desiredVersion); + //when + client.execute(chartPath.toString(), "".getBytes(), helmValidatorConfig); + //then + verify(httpRequestHandler).post(any(), any(), httpEntityCaptor.capture(), any()); + + Object[] testArgs = {chartPath, "", false, false, desiredVersion}; + String expectedHttpEntityContent = new MessageFormat(HTTP_ENTITY_PATTERN).format(testArgs); + String actualHttpEntityContent = getHttpEntityContent(); + + assertEquals(expectedHttpEntityContent, actualHttpEntityContent); + + } + + @ParameterizedTest + @CsvSource({"fileName,chart content 123", "b,content", "chart,12345\n21234"}) + void shouldPrepareRequestWithChartFromConfig(String testChartFileName, String testChartContent) + throws Exception { + //given + Path chartPath = getTestPath(testChartFileName, testChartContent); + //when + client.execute(chartPath.toString(), testChartContent.getBytes(), helmValidatorConfig); + //then + verify(httpRequestHandler).post(any(), any(), httpEntityCaptor.capture(), any()); + + Object[] testArgs = {chartPath, testChartContent, false, false, "3.5.6"}; + String expectedHttpEntityContent = new MessageFormat(HTTP_ENTITY_PATTERN).format(testArgs); + String actualHttpEntityContent = getHttpEntityContent(); + + assertEquals(expectedHttpEntityContent, actualHttpEntityContent); + } + + @Test + void shouldPrepareLintableRequest() throws Exception { + //given + Path chartPath = getTestPath(TEST_CHART_FILE_NAME, ""); + when(helmValidatorConfig.isLintable()).thenReturn(true); + //when + client.execute(chartPath.toString(), "".getBytes(), helmValidatorConfig); + //then + verify(httpRequestHandler).post(any(), any(), httpEntityCaptor.capture(), any()); + + Object[] testArgs = {chartPath, "", true, false, "3.5.6"}; + String expectedHttpEntityContent = new MessageFormat(HTTP_ENTITY_PATTERN).format(testArgs); + String actualHttpEntityContent = getHttpEntityContent(); + + assertEquals(expectedHttpEntityContent, actualHttpEntityContent); + } + + @Test + void shouldPrepareStrictLintableRequest() throws Exception { + //given + Path chartPath = getTestPath(TEST_CHART_FILE_NAME, ""); + when(helmValidatorConfig.isStrictLintable()).thenReturn(true); + //when + client.execute(chartPath.toString(), "".getBytes(), helmValidatorConfig); + //then + verify(httpRequestHandler).post(any(), any(), httpEntityCaptor.capture(), any()); + + Object[] testArgs = {chartPath, "", false, true, "3.5.6"}; + String expectedHttpEntityContent = new MessageFormat(HTTP_ENTITY_PATTERN).format(testArgs); + String actualHttpEntityContent = getHttpEntityContent(); + + assertEquals(expectedHttpEntityContent, actualHttpEntityContent); + } + + private Path getTestPath(String testChartFileName, String testChartContent) throws IOException { + Path chartPath = tempDir.resolve(testChartFileName); + Files.writeString(chartPath, testChartContent); + return chartPath; + } + + private String getHttpEntityContent() throws IOException { + final var httpEntityCaptorValue = httpEntityCaptor.getValue(); + try (InputStream content = httpEntityCaptorValue.getContent()) { + BufferedReader reader = new BufferedReader(new InputStreamReader(content, HTTP.DEF_CONTENT_CHARSET)); + return reader.lines() + .filter( + line -> line.startsWith("Content-Disposition:") || (!line.contains(":") && !line.contains("--"))) + .collect(Collectors.joining(" ")); + } + } +} diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/GlobalContextUtilTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/GlobalContextUtilTest.java index df6fa0676f..c4d718ab12 100644 --- a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/GlobalContextUtilTest.java +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/GlobalContextUtilTest.java @@ -20,14 +20,14 @@ package org.openecomp.sdc.validation.impl.validators; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Set; import org.junit.jupiter.api.Test; import org.openecomp.core.validation.types.GlobalValidationContext; +import org.openecomp.sdc.heat.datatypes.manifest.FileData.Type; import org.openecomp.sdc.validation.util.ValidationTestUtil; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; - class GlobalContextUtilTest { private static final String TEST_MANIFEST_PATH = "/org/openecomp/validation/validators/global_context_util/"; @@ -37,7 +37,7 @@ class GlobalContextUtilTest { GlobalValidationContext globalContext = new ValidationTestUtil().createGlobalContextFromPath(TEST_MANIFEST_PATH); // when - Set<String> pmDictionaryFiles = GlobalContextUtil.findPmDictionaryFiles(globalContext); + Set<String> pmDictionaryFiles = GlobalContextUtil.findFilesByType(globalContext, Type.PM_DICTIONARY); // then assertEquals(1, pmDictionaryFiles.size()); diff --git a/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/HelmValidatorTest.java b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/HelmValidatorTest.java new file mode 100644 index 0000000000..f639acafab --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-validation-lib/openecomp-sdc-validation-impl/src/test/java/org/openecomp/sdc/validation/impl/validators/HelmValidatorTest.java @@ -0,0 +1,141 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nokia + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.openecomp.sdc.validation.impl.validators; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.nio.file.Files; +import java.nio.file.Path; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.openecomp.sdc.common.http.client.api.HttpResponse; +import org.openecomp.sdc.datatypes.error.ErrorLevel; +import org.openecomp.sdc.validation.impl.util.HelmValidatorHttpClient; +import org.openecomp.sdc.validation.type.helmvalidator.HelmValidatorConfig; +import org.openecomp.sdc.validation.util.ValidationTestUtil; + +@ExtendWith(MockitoExtension.class) +class HelmValidatorTest { + + private static final String RESOURCE_PATH = "/org/openecomp/validation/validators/helm_validator"; + private static final String VALIDATOR_RESPONSE_WITH_ERRORS = "{\"renderErrors\":[\"[ERROR] render error\"],\"" + + "lintWarning\":[\"[WARNING] warning\"]," + + "\"lintError\":[\"[ERROR] lint error\"]," + + "\"versionUsed\":\"3.5.2\",\"valid\":false,\"deployable\":true}"; + private static final String VALIDATOR_RESPONSE_WITHOUT_LINTING = "{\"renderErrors\":[\"[ERROR] render error 1\"]," + + "\"versionUsed\":\"3.5.2\",\"valid\":false,\"deployable\":true}"; + private static final String VALIDATOR_ERROR_RESPONSE = "{\"message\":\"Error response message\"}"; + private static final String TEST_RESOURCES = "./src/test/resources/"; + + @InjectMocks + private HelmValidator validator; + @Mock + private HelmValidatorHttpClient helmValidatorHttpClient; + @Mock + private HelmValidatorConfig helmValidatorConfig; + + @Test + void shouldCallHelmValidatorForEveryChartWhenIsEnabled() throws Exception { + when(helmValidatorConfig.isEnabled()).thenReturn(true); + String chartPath = RESOURCE_PATH + "/valid_two_charts"; + + var messages = new ValidationTestUtil().testValidator(validator, chartPath); + + byte[] firstChartContent = Files.readAllBytes(Path.of(TEST_RESOURCES + chartPath + "/chart1.tgz")); + byte[] secondChartContent = Files.readAllBytes(Path.of(TEST_RESOURCES + chartPath + "/chart2.tgz")); + verify(helmValidatorHttpClient).execute("chart1.tgz", firstChartContent, helmValidatorConfig); + verify(helmValidatorHttpClient).execute("chart2.tgz", secondChartContent, helmValidatorConfig); + verify(helmValidatorHttpClient, times(2)).execute(any(), any(), any()); + assertEquals(2, messages.size()); + } + + @Test + void shouldNotCallHelmValidatorClientWhenIsDisabled() throws Exception { + when(helmValidatorConfig.isEnabled()).thenReturn(false); + String chartPath = RESOURCE_PATH + "/valid_two_charts"; + + var messages = new ValidationTestUtil().testValidator(validator, chartPath); + + verify(helmValidatorHttpClient, times(0)).execute(any(), any(), any()); + assertEquals(0, messages.size()); + } + + @Test + void shouldContainsMessagesForEveryChartWhenIsEnabled() throws Exception { + when(helmValidatorConfig.isEnabled()).thenReturn(true); + String chartPath = RESOURCE_PATH + "/valid_two_charts"; + when(helmValidatorHttpClient.execute(eq("chart1.tgz"), any(), any())) + .thenReturn(new HttpResponse<>(VALIDATOR_RESPONSE_WITH_ERRORS, 200)); + when(helmValidatorHttpClient.execute(eq("chart2.tgz"), any(), any())) + .thenReturn(new HttpResponse<>(VALIDATOR_RESPONSE_WITHOUT_LINTING, 200)); + + var messages = new ValidationTestUtil().testValidator(validator, chartPath); + + assertEquals(2, messages.size()); + var firstChartErrors = messages.get("chart1.tgz").getErrorMessageList(); + var secondChartErrors = messages.get("chart2.tgz").getErrorMessageList(); + assertEquals(3, firstChartErrors.size()); + assertEquals(1, secondChartErrors.size()); + assertEquals("ERROR: [HELM VALIDATOR]: [ERROR] render error", firstChartErrors.get(0).getMessage()); + assertEquals("WARNING: [HELM VALIDATOR]: [ERROR] lint error", firstChartErrors.get(1).getMessage()); + assertEquals("WARNING: [HELM VALIDATOR]: [WARNING] warning", firstChartErrors.get(2).getMessage()); + assertEquals("ERROR: [HELM VALIDATOR]: [ERROR] render error 1", secondChartErrors.get(0).getMessage()); + } + + @Test + void shouldCorectlySetErrorsAndWarningsFromHelmValidator() throws Exception { + String validChartPath = RESOURCE_PATH + "/valid_chart"; + when(helmValidatorConfig.isEnabled()).thenReturn(true); + when(helmValidatorHttpClient.execute(any(), any(), any())) + .thenReturn(new HttpResponse<>(VALIDATOR_RESPONSE_WITH_ERRORS, 200)); + + var messages = new ValidationTestUtil().testValidator(validator, validChartPath); + + var chartErrors = messages.get("chart.tgz").getErrorMessageList(); + assertEquals(1, messages.size()); + assertEquals(3, chartErrors.size()); + assertEquals("ERROR: [HELM VALIDATOR]: [ERROR] render error", chartErrors.get(0).getMessage()); + assertEquals("WARNING: [HELM VALIDATOR]: [ERROR] lint error", chartErrors.get(1).getMessage()); + assertEquals("WARNING: [HELM VALIDATOR]: [WARNING] warning", chartErrors.get(2).getMessage()); + } + + @Test + void shouldAddWarningWhenErrorResponseFromValidator() throws Exception { + String chartPath = RESOURCE_PATH + "/valid_chart"; + when(helmValidatorConfig.isEnabled()).thenReturn(true); + when(helmValidatorHttpClient.execute(any(), any(), any())) + .thenReturn(new HttpResponse<>(VALIDATOR_ERROR_RESPONSE, 400)); + + var messages = new ValidationTestUtil().testValidator(validator, chartPath); + + var chartErrors = messages.get("chart.tgz").getErrorMessageList(); + assertEquals(1, chartErrors.size()); + assertEquals(ErrorLevel.WARNING, chartErrors.get(0).getLevel()); + assertEquals("WARNING: [HELM VALIDATOR]: Error response message", chartErrors.get(0).getMessage()); + } + +} |