Skip to content

Commit

Permalink
feat(artifacts): Updates to tests due to Helm util constructor changes
Browse files Browse the repository at this point in the history
Signed-off-by: benjamin-j-powell <bjp@apple.com>
  • Loading branch information
benjamin-j-powell committed Feb 3, 2024
1 parent ad5f0c0 commit f9e9b9a
Show file tree
Hide file tree
Showing 2 changed files with 174 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.netflix.spinnaker.kork.artifacts.artifactstore.ArtifactStore;
import com.netflix.spinnaker.kork.artifacts.artifactstore.ArtifactStoreConfigurationProperties;
import com.netflix.spinnaker.kork.artifacts.model.Artifact;
import com.netflix.spinnaker.kork.exceptions.SpinnakerException;
import com.netflix.spinnaker.kork.retrofit.exceptions.SpinnakerHttpException;
Expand All @@ -47,6 +49,9 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
Expand All @@ -70,14 +75,27 @@ final class HelmTemplateUtilsTest {

private HelmBakeManifestRequest bakeManifestRequest;

/**
* Configuration for the default values in the event artifact store had been
* turned off.
*/
private ArtifactStoreConfigurationProperties artifactStoreConfig;

@BeforeEach
private void init(TestInfo testInfo) {
System.out.println("--------------- Test " + testInfo.getDisplayName());

artifactDownloader = mock(ArtifactDownloader.class);
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
helmTemplateUtils = new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
artifactStoreConfig = new ArtifactStoreConfigurationProperties();
ArtifactStoreConfigurationProperties.HelmConfig helmConfig =
new ArtifactStoreConfigurationProperties.HelmConfig();
artifactStoreConfig.setHelm(helmConfig);
helmConfig.setExpandOverrides(false);
helmTemplateUtils =
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);
Artifact chartArtifact = Artifact.builder().name("test-artifact").version("3").build();

bakeManifestRequest = new HelmBakeManifestRequest();
Expand Down Expand Up @@ -154,7 +172,8 @@ public void removeTestsDirectoryTemplatesWithTests() throws IOException {
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);

String output = helmTemplateUtils.removeTestsDirectoryTemplates(inputManifests);

Expand Down Expand Up @@ -208,7 +227,8 @@ public void removeTestsDirectoryTemplatesWithoutTests() throws IOException {
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);

String output = helmTemplateUtils.removeTestsDirectoryTemplates(inputManifests);

Expand All @@ -223,7 +243,8 @@ public void buildBakeRecipeSelectsHelmExecutableByVersion(
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);

HelmBakeManifestRequest request = new HelmBakeManifestRequest();
Artifact artifact = Artifact.builder().build();
Expand Down Expand Up @@ -256,7 +277,8 @@ public void buildBakeRecipeWithGitRepoArtifact(@TempDir Path tempDir) throws IOE
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);

HelmBakeManifestRequest request = new HelmBakeManifestRequest();

Expand Down Expand Up @@ -296,7 +318,8 @@ public void buildBakeRecipeWithGitRepoArtifactUsingHelmChartFilePath(@TempDir Pa
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);

HelmBakeManifestRequest request = new HelmBakeManifestRequest();

Expand Down Expand Up @@ -356,7 +379,8 @@ public void buildBakeRecipeIncludingHelmVersionsOptionsWithHelm3() throws IOExce
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);

HelmBakeManifestRequest request = new HelmBakeManifestRequest();
Artifact artifact = Artifact.builder().build();
Expand All @@ -381,7 +405,8 @@ public void buildBakeRecipeIncludingHelmVersionsOptionsWithHelm2() throws IOExce
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);

HelmBakeManifestRequest request = new HelmBakeManifestRequest();
Artifact artifact = Artifact.builder().build();
Expand All @@ -406,7 +431,8 @@ public void buildBakeRecipeIncludingCRDsWithHelm3() throws IOException {
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);

HelmBakeManifestRequest request = new HelmBakeManifestRequest();
Artifact artifact = Artifact.builder().build();
Expand All @@ -423,6 +449,54 @@ public void buildBakeRecipeIncludingCRDsWithHelm3() throws IOException {
}
}

@ParameterizedTest
@MethodSource("ensureOverrides")
public void ensureOverridesGetEvaluated(
String reference,
Map<String, Object> overrides,
String expected,
Boolean artifactStoreNull,
Boolean expandOverrides) {
ArtifactStore artifactStore = null;
if (!artifactStoreNull) {
artifactStore = mock(ArtifactStore.class);
when(artifactStore.get(any())).thenReturn(Artifact.builder().reference(reference).build());
}
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();

// do not use the artifactStoreConfig field as we are trying to test various
// values of expandOverrides
ArtifactStoreConfigurationProperties artifactStoreConfiguration =
new ArtifactStoreConfigurationProperties();
ArtifactStoreConfigurationProperties.HelmConfig helmConfig =
new ArtifactStoreConfigurationProperties.HelmConfig();
helmConfig.setExpandOverrides(expandOverrides);
artifactStoreConfiguration.setHelm(helmConfig);

HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(
artifactDownloader,
Optional.ofNullable(artifactStore),
artifactStoreConfiguration,
helmConfigurationProperties);
HelmBakeManifestRequest request = new HelmBakeManifestRequest();
request.setOutputName("output_name");
request.setTemplateRenderer(BakeManifestRequest.TemplateRenderer.HELM3);
request.setOverrides(overrides);
BakeRecipe recipe =
helmTemplateUtils.buildCommand(request, List.of(), Path.of("template_path"));

assertThat(recipe.getCommand().contains(expected)).isTrue();
}

private static Stream<Arguments> ensureOverrides() {
return Stream.of(
Arguments.of("test", Map.of("foo", "ref://bar/baz"), "foo=test", false, true),
Arguments.of("test", Map.of("foo", "ref://bar/baz"), "foo=ref://bar/baz", false, false),
Arguments.of("test", Map.of("foo", "ref://bar/baz"), "foo=ref://bar/baz", true, false));
}

@ParameterizedTest
@MethodSource("helmRendererArgsCRDs")
public void buildBakeRecipeNotIncludingCRDs(
Expand All @@ -432,7 +506,8 @@ public void buildBakeRecipeNotIncludingCRDs(
RoscoHelmConfigurationProperties helmConfigurationProperties =
new RoscoHelmConfigurationProperties();
HelmTemplateUtils helmTemplateUtils =
new HelmTemplateUtils(artifactDownloader, helmConfigurationProperties);
new HelmTemplateUtils(
artifactDownloader, Optional.empty(), artifactStoreConfig, helmConfigurationProperties);

HelmBakeManifestRequest request = new HelmBakeManifestRequest();
Artifact artifact = Artifact.builder().build();
Expand Down
Loading

0 comments on commit f9e9b9a

Please sign in to comment.