diff --git a/pkg/skaffold/deploy/helm.go b/pkg/skaffold/deploy/helm.go index 7596de9f001..4b01602f06a 100644 --- a/pkg/skaffold/deploy/helm.go +++ b/pkg/skaffold/deploy/helm.go @@ -25,6 +25,7 @@ import ( "os" "os/exec" "path/filepath" + "sort" "strconv" "strings" @@ -89,6 +90,7 @@ func (h *HelmDeployer) Dependencies() ([]string, error) { return nil }) } + sort.Strings(deps) return deps, nil } diff --git a/pkg/skaffold/deploy/helm_test.go b/pkg/skaffold/deploy/helm_test.go index f7cff7ab123..eb2ca6943b8 100644 --- a/pkg/skaffold/deploy/helm_test.go +++ b/pkg/skaffold/deploy/helm_test.go @@ -24,9 +24,6 @@ import ( "io/ioutil" "os" "os/exec" - "path/filepath" - "reflect" - "sort" "strings" "testing" @@ -355,6 +352,7 @@ func TestHelmDeploy(t *testing.T) { util.DefaultExecCommand = tt.cmd _, err := tt.deployer.Deploy(context.Background(), &bytes.Buffer{}, tt.builds) + testutil.CheckError(t, tt.shouldErr, err) }) } @@ -435,20 +433,18 @@ func TestParseHelmRelease(t *testing.T) { shouldErr bool }{ { - name: "parse valid deployment yaml", - yaml: []byte(validDeployYaml), - shouldErr: false, + name: "parse valid deployment yaml", + yaml: []byte(validDeployYaml), + }, + { + name: "parse valid service yaml", + yaml: []byte(validServiceYaml), }, { name: "parse invalid deployment yaml", yaml: []byte(invalidDeployYaml), shouldErr: true, }, - { - name: "parse valid service yaml", - yaml: []byte(validServiceYaml), - shouldErr: false, - }, } for _, tt := range tests { @@ -460,50 +456,12 @@ func TestParseHelmRelease(t *testing.T) { } func TestExtractChartFilename(t *testing.T) { - testCases := map[string]struct { - input string - tmp string - output string - shouldErr bool - }{ - "1": { - input: "Successfully packaged chart and saved it to: /var/folders/gm/rrs_712142x8vymmd7xq7h340000gn/T/foo-1.2.3-dirty.tgz\n", - tmp: "/var/folders/gm/rrs_712142x8vymmd7xq7h340000gn/T/", - output: "foo-1.2.3-dirty.tgz", - shouldErr: false, - }, - } + out, err := extractChartFilename( + "Successfully packaged chart and saved it to: /var/folders/gm/rrs_712142x8vymmd7xq7h340000gn/T/foo-1.2.3-dirty.tgz\n", + "/var/folders/gm/rrs_712142x8vymmd7xq7h340000gn/T/", + ) - for name, tc := range testCases { - t.Run(name, func(t *testing.T) { - out, err := extractChartFilename(tc.input, tc.tmp) - testutil.CheckError(t, tc.shouldErr, err) - if out != tc.output { - t.Errorf("Expected output to be %q but got %q", tc.output, out) - } - }) - } -} - -func testDeployConfigWithPaths(chartPath string, valuesFilePath string) *v1alpha2.HelmDeploy { - return &v1alpha2.HelmDeploy{ - Releases: []v1alpha2.HelmRelease{ - { - Name: "skaffold-helm", - ChartPath: chartPath, - ValuesFilePath: valuesFilePath, - Values: map[string]string{ - "image": "skaffold-helm", - }, - Overrides: map[string]interface{}{ - "foo": "bar", - }, - SetValues: map[string]string{ - "some.key": "somevalue", - }, - }, - }, - } + testutil.CheckErrorAndDeepEqual(t, false, err, "foo-1.2.3-dirty.tgz", out) } func TestHelmDependencies(t *testing.T) { @@ -511,21 +469,21 @@ func TestHelmDependencies(t *testing.T) { description string files []string valuesFilePath string - output func(folder *testutil.TempDir) []string + expected func(folder *testutil.TempDir) []string }{ { description: "charts dir is excluded", files: []string{"Chart.yaml", "charts/xyz.tar", "templates/deploy.yaml"}, - output: func(folder *testutil.TempDir) []string { - return []string{filepath.Join(folder.Root(), "Chart.yaml"), filepath.Join(folder.Root(), "templates/deploy.yaml")} + expected: func(folder *testutil.TempDir) []string { + return []string{folder.Path("Chart.yaml"), folder.Path("templates/deploy.yaml")} }, }, { description: "values file is included", files: []string{"Chart.yaml"}, - valuesFilePath: "/tmp/values.yaml", - output: func(folder *testutil.TempDir) []string { - return []string{filepath.Join(folder.Root(), "Chart.yaml"), "/tmp/values.yaml"} + valuesFilePath: "/folder/values.yaml", + expected: func(folder *testutil.TempDir) []string { + return []string{"/folder/values.yaml", folder.Path("Chart.yaml")} }, }, } @@ -534,18 +492,26 @@ func TestHelmDependencies(t *testing.T) { t.Run(tt.description, func(t *testing.T) { folder, cleanup := testutil.NewTempDir(t) defer cleanup() - deployer := NewHelmDeployer(testDeployConfigWithPaths(folder.Root(), tt.valuesFilePath), testKubeContext, testNamespace) for _, file := range tt.files { - folder.Write(file, "test") + folder.Write(file, "") } - deps, _ := deployer.Dependencies() - output := tt.output(folder) - sort.Strings(output) - sort.Strings(deps) - if !reflect.DeepEqual(deps, output) { - t.Errorf("Expected chart dependencies to be %q but got %q", output, deps) - } + deployer := NewHelmDeployer(&v1alpha2.HelmDeploy{ + Releases: []v1alpha2.HelmRelease{ + { + Name: "skaffold-helm", + ChartPath: folder.Root(), + ValuesFilePath: tt.valuesFilePath, + Values: map[string]string{"image": "skaffold-helm"}, + Overrides: map[string]interface{}{"foo": "bar"}, + SetValues: map[string]string{"some.key": "somevalue"}, + }, + }, + }, testKubeContext, testNamespace) + + deps, err := deployer.Dependencies() + + testutil.CheckErrorAndDeepEqual(t, false, err, tt.expected(folder), deps) }) } }