Skip to content

Commit

Permalink
Add integration tests for make version var in package chart rule
Browse files Browse the repository at this point in the history
  • Loading branch information
danigar committed Jan 16, 2020
1 parent 7edfb99 commit 41d305f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/charts/nginx/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ helm_chart(
values_repo_yaml_path = "image.repository"
)

helm_chart(
name = "nginx_chart_make_version",
srcs = glob(["**"]),
image_tag = "nginx",
image_repository = "nginx",
helm_chart_version = "{TEST_VERSION}",
package_name = "nginx",
values_tag_yaml_path = "image.tag",
values_repo_yaml_path = "image.repository"
)

helm_release(
name = "nginx_helm_release",
chart = ":nginx_chart",
Expand Down
52 changes: 52 additions & 0 deletions tests/rules/package_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,55 @@ func TestChartPackageImageTagMakeVar(t *testing.T) {
require.Equal(t, deployment.Spec.Template.Spec.Containers[0].Image, image_repository+":"+imageTag)

}

func TestChartPackageChartVersionMakeVar(t *testing.T) {
t.Parallel()

chartVersion := "0.0.2"
chartTarPackagePath := "bazel-bin/tests/charts/nginx/nginx-" + chartVersion + ".tgz"
chartPackageRootPath := "nginx"
relativeChartPackageRootPath := "../../" + chartPackageRootPath

shell.RunCommand(t, shell.Command{
Command: "bazel",
Args: []string{"build", "//tests/charts/nginx:nginx_chart_make_version", "--define", "TEST_VERSION=" + chartVersion},
WorkingDir: ".",
Env: map[string]string{},
OutputMaxLineSize: 1024,
})

shell.RunCommand(t, shell.Command{
Command: "tar",
Args: []string{"-xzf", chartTarPackagePath},
WorkingDir: "../..",
Env: map[string]string{},
OutputMaxLineSize: 1024,
})

defer shell.RunCommand(t, shell.Command{
Command: "rm",
Args: []string{"-f", chartTarPackagePath},
WorkingDir: "../..",
Env: map[string]string{},
OutputMaxLineSize: 1024,
})

defer shell.RunCommand(t, shell.Command{
Command: "rm",
Args: []string{"-rf", chartPackageRootPath},
WorkingDir: "../..",
Env: map[string]string{},
OutputMaxLineSize: 1024,
})

output := helm.RenderTemplate(t, &helm.Options{
ValuesFiles: []string{
relativeChartPackageRootPath + "/values.yaml",
},
}, relativeChartPackageRootPath, "nginx", []string{"templates/deployment.yaml"})

var deployment appsv1.Deployment
helm.UnmarshalK8SYaml(t, output, &deployment)

require.Equal(t, deployment.ObjectMeta.Labels["version"], chartVersion)
}

0 comments on commit 41d305f

Please sign in to comment.