From bfc0d76fff148865aa1e9d5ba28693da2947b4fe Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Wed, 16 Jan 2019 17:31:36 -0500 Subject: [PATCH 1/2] fix(helm): allow lint to parse pre-release charts The lint command cannot parse a compressed chart with a pre-release version, e.g. 0.1.0-alhpa: it errors out saying it cannot find the Chart.yaml file. This is due to the way the lint command identifies the chart dir name, i.e. using the last hyphen in the name of the compressed file. Changing this method to using the name of the single directory with the chart's name, as expected from decompressing a chart, allows lint to parse pre-release charts. Signed-off-by: Arash Deshmeh --- cmd/helm/lint.go | 13 ++++++++----- cmd/helm/lint_test.go | 5 +++++ .../testcharts/pre-release-chart-0.1.0-alpha.tgz | Bin 0 -> 355 bytes pkg/chartutil/expand_test.go | 13 +++++++++++++ 4 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 cmd/helm/testdata/testcharts/pre-release-chart-0.1.0-alpha.tgz diff --git a/cmd/helm/lint.go b/cmd/helm/lint.go index d0159d34b..2736cb524 100644 --- a/cmd/helm/lint.go +++ b/cmd/helm/lint.go @@ -156,12 +156,15 @@ func lintChart(path string, vals []byte, namespace string, strict bool) (support return linter, err } - lastHyphenIndex := strings.LastIndex(filepath.Base(path), "-") - if lastHyphenIndex <= 0 { - return linter, fmt.Errorf("unable to parse chart archive %q, missing '-'", filepath.Base(path)) + files, err := ioutil.ReadDir(tempDir) + if err != nil { + return linter, fmt.Errorf("unable to read temporary output directory %s", tempDir) + } + if !files[0].IsDir() { + return linter, fmt.Errorf("unexpected file %s in temporary output directory %s", files[0].Name(), tempDir) } - base := filepath.Base(path)[:lastHyphenIndex] - chartPath = filepath.Join(tempDir, base) + + chartPath = filepath.Join(tempDir, files[0].Name()) } else { chartPath = path } diff --git a/cmd/helm/lint_test.go b/cmd/helm/lint_test.go index 67775893b..c45400601 100644 --- a/cmd/helm/lint_test.go +++ b/cmd/helm/lint_test.go @@ -29,6 +29,7 @@ var ( invalidArchivedChartPath = "testdata/testcharts/invalidcompressedchart0.1.0.tgz" chartDirPath = "testdata/testcharts/decompressedchart/" chartMissingManifest = "testdata/testcharts/chart-missing-manifest" + chartWithPreReleaseVersion = "testdata/testcharts/pre-release-chart-0.1.0-alpha.tgz" ) func TestLintChart(t *testing.T) { @@ -44,6 +45,10 @@ func TestLintChart(t *testing.T) { t.Errorf("%s", err) } + if _, err := lintChart(chartWithPreReleaseVersion, values, namespace, strict); err != nil { + t.Errorf("%s", err) + } + if _, err := lintChart(invalidArchivedChartPath, values, namespace, strict); err == nil { t.Errorf("Expected a chart parsing error") } diff --git a/cmd/helm/testdata/testcharts/pre-release-chart-0.1.0-alpha.tgz b/cmd/helm/testdata/testcharts/pre-release-chart-0.1.0-alpha.tgz new file mode 100644 index 0000000000000000000000000000000000000000..5d5770fed227de5f776eb9080eb377aad6293c1b GIT binary patch literal 355 zcmV-p0i6CHiwG0|00000|0w_~VMtOiV@ORlOnEsqVl!4SWK%V1T2nbTPgYhoO;>Dc zVQyr3R8em|NM&qo0PK{zYV$x4g;nb*23$-3NWU)N&csC^NtY(&SQ_DlU9Ff|8T|G^ za%V#lh=@thS7=o1ZFbK&gK#2jnUs^}ND}@%OyBfO&PEG?h*+29ToLiQVwP7?_P@yL zI1Ma8b~7i_FmV`{SsQ%M$8b5@3*jnN45@T9YE&=p2h=9&w(}W z$?+C$9uN+r2y|ofk(Ta0{KWJPp`$V@VjMq`0UE1~Q@$ zJRGL~X*n=`@No8{Kwvjm3an`imvnLG Date: Wed, 16 Jan 2019 18:03:33 -0500 Subject: [PATCH 2/2] fix(helm): refactor lint unit tests to table-driven Signed-off-by: Arash Deshmeh --- cmd/helm/lint_test.go | 75 +++++++++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 31 deletions(-) diff --git a/cmd/helm/lint_test.go b/cmd/helm/lint_test.go index c45400601..fc40151b8 100644 --- a/cmd/helm/lint_test.go +++ b/cmd/helm/lint_test.go @@ -20,40 +20,53 @@ import ( "testing" ) -var ( - values = []byte{} - namespace = "testNamespace" - strict = false - archivedChartPath = "testdata/testcharts/compressedchart-0.1.0.tgz" - archivedChartPathWithHyphens = "testdata/testcharts/compressedchart-with-hyphens-0.1.0.tgz" - invalidArchivedChartPath = "testdata/testcharts/invalidcompressedchart0.1.0.tgz" - chartDirPath = "testdata/testcharts/decompressedchart/" - chartMissingManifest = "testdata/testcharts/chart-missing-manifest" - chartWithPreReleaseVersion = "testdata/testcharts/pre-release-chart-0.1.0-alpha.tgz" -) - func TestLintChart(t *testing.T) { - if _, err := lintChart(chartDirPath, values, namespace, strict); err != nil { - t.Errorf("%s", err) + tests := []struct { + name string + chartPath string + err bool + }{ + { + name: "decompressed-chart", + chartPath: "testdata/testcharts/decompressedchart/", + }, + { + name: "archived-chart-path", + chartPath: "testdata/testcharts/compressedchart-0.1.0.tgz", + }, + { + name: "archived-chart-path-with-hyphens", + chartPath: "testdata/testcharts/compressedchart-with-hyphens-0.1.0.tgz", + }, + { + name: "pre-release-chart", + chartPath: "testdata/testcharts/pre-release-chart-0.1.0-alpha.tgz", + }, + { + name: "invalid-archived-chart-path", + chartPath: "testdata/testcharts/invalidcompressedchart0.1.0.tgz", + err: true, + }, + { + name: "chart-missing-manifest", + chartPath: "testdata/testcharts/chart-missing-manifest", + err: true, + }, } - if _, err := lintChart(archivedChartPath, values, namespace, strict); err != nil { - t.Errorf("%s", err) - } - - if _, err := lintChart(archivedChartPathWithHyphens, values, namespace, strict); err != nil { - t.Errorf("%s", err) - } - - if _, err := lintChart(chartWithPreReleaseVersion, values, namespace, strict); err != nil { - t.Errorf("%s", err) - } - - if _, err := lintChart(invalidArchivedChartPath, values, namespace, strict); err == nil { - t.Errorf("Expected a chart parsing error") - } + values := []byte{} + namespace := "testNamespace" + strict := false - if _, err := lintChart(chartMissingManifest, values, namespace, strict); err == nil { - t.Errorf("Expected a chart parsing error") + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + _, err := lintChart(tt.chartPath, values, namespace, strict) + switch { + case err != nil && !tt.err: + t.Errorf("%s", err) + case err == nil && tt.err: + t.Errorf("Expected a chart parsing error") + } + }) } }