From 764c3187e9d1e355513a064ffc8e151a1228b27f Mon Sep 17 00:00:00 2001 From: Arash Deshmeh Date: Wed, 16 Jan 2019 18:03:33 -0500 Subject: [PATCH] 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") + } + }) } }