Skip to content

Commit

Permalink
Merge pull request #1486 from gruntwork-io/fix-render-remote-template
Browse files Browse the repository at this point in the history
Fixing the TestRemoteChartRender Unit Test failure by pecifing remote chart version
  • Loading branch information
james03160927 authored Dec 12, 2024
2 parents 1389227 + 16160ea commit 810156e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions modules/helm/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ func RenderRemoteTemplateE(t testing.TestingT, options *Options, chartURL string

// ... and add the helm chart name, the remote repo and chart URL at the end
args = append(args, releaseName, "--repo", chartURL)
if options.Version != "" {
args = append(args, "--version", options.Version)
}

// Finally, call out to helm template command
return RunHelmCommandAndGetStdOutE(t, options, "template", args...)
Expand Down
15 changes: 9 additions & 6 deletions modules/helm/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestRemoteChartRender(t *testing.T) {
remoteChartSource = "https://charts.bitnami.com/bitnami"
remoteChartName = "nginx"
remoteChartVersion = "13.2.24"
registry = "registry-1.docker.io"
)

t.Parallel()
Expand All @@ -42,11 +43,12 @@ func TestRemoteChartRender(t *testing.T) {
options := &Options{
SetValues: map[string]string{
"image.repository": remoteChartName,
"image.registry": "",
"image.registry": registry,
"image.tag": remoteChartVersion,
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
Logger: logger.Discard,
Version: remoteChartVersion,
}

// Run RenderTemplate to render the template and capture the output. Note that we use the version without `E`, since
Expand All @@ -62,10 +64,10 @@ func TestRemoteChartRender(t *testing.T) {
require.Equal(t, namespaceName, deployment.Namespace)

// Finally, we verify the deployment pod template spec is set to the expected container image value
expectedContainerImage := remoteChartName + ":" + remoteChartVersion
expectedContainerImage := registry + "/" + remoteChartName + ":" + remoteChartVersion
deploymentContainers := deployment.Spec.Template.Spec.Containers
require.Equal(t, len(deploymentContainers), 1)
require.Equal(t, deploymentContainers[0].Image, expectedContainerImage)
require.Equal(t, expectedContainerImage, deploymentContainers[0].Image)
}

// Test that we can dump all the manifest locally a remote chart (e.g bitnami/nginx)
Expand All @@ -81,15 +83,15 @@ func TestRemoteChartRenderDiff(t *testing.T) {

initialSnapshot := t.TempDir()
updatedSnapshot := t.TempDir()
renderChartDump(t, "5.0.0", initialSnapshot)
output := renderChartDump(t, "5.1.0", updatedSnapshot)
renderChartDump(t, "13.2.20", initialSnapshot)
output := renderChartDump(t, "13.2.24", updatedSnapshot)

options := &Options{
Logger: logger.Default,
SnapshotPath: initialSnapshot,
}
// diff in: spec.initContainers.preserve-logs-symlinks.imag, spec.containers.nginx.image, tls certificates
require.Equal(t, 5, DiffAgainstSnapshot(t, options, output, "nginx"))
require.Equal(t, 4, DiffAgainstSnapshot(t, options, output, "nginx"))
}

// render chart dump and return the rendered output
Expand All @@ -111,6 +113,7 @@ func renderChartDump(t *testing.T, remoteChartVersion, snapshotDir string) strin
},
KubectlOptions: k8s.NewKubectlOptions("", "", namespaceName),
Logger: logger.Discard,
Version: remoteChartVersion,
}

// Run RenderTemplate to render the template and capture the output. Note that we use the version without `E`, since
Expand Down

0 comments on commit 810156e

Please sign in to comment.