From b869a50056778c7b99f81587eedee828b8680302 Mon Sep 17 00:00:00 2001 From: wujunwei Date: Thu, 17 Nov 2022 20:13:20 +0800 Subject: [PATCH] fix some typo. Signed-off-by: wujunwei --- cmd/helm/template.go | 4 +++- cmd/helm/template_test.go | 28 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cmd/helm/template.go b/cmd/helm/template.go index bc70d46c0..8ccc60596 100644 --- a/cmd/helm/template.go +++ b/cmd/helm/template.go @@ -112,6 +112,8 @@ func newTemplateCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { // with globs or directory names. splitManifests := releaseutil.SplitManifests(manifests.String()) manifestsKeys := make([]string, 0, len(splitManifests)) + // such as `# Source: subchart/templates/service.yaml` will be divided into two parts `subchart/`, `templates/service.yaml` + // and manifestName will be `templates/service.yaml` , manifestPath will be `subchart/templates/service.yam` manifestNameRegex := regexp.MustCompile("# Source: ([^/]+/)(.+)") for k := range splitManifests { manifestsKeys = append(manifestsKeys, k) @@ -229,7 +231,7 @@ func matchFilePatterns(target string, sf []string) bool { return false } -// writeManifest write manifest to stdout or file stream. use withHeader to control if write file header `# Source: XXXXX.yaml` or not. +// writeManifest write manifest to stdout or file stream. use withHeader to control if write file header `# Source: XXXXX.yaml`. func writeManifest(outputDir, path, manifest string, fileWritten map[string]bool, withHeader bool, outStream io.Writer) error { if outputDir == "" { return writeStream(path, manifest, withHeader, outStream) diff --git a/cmd/helm/template_test.go b/cmd/helm/template_test.go index 87c5a6b9a..58a1cd7ec 100644 --- a/cmd/helm/template_test.go +++ b/cmd/helm/template_test.go @@ -176,7 +176,7 @@ func TestTemplateOutputDir(t *testing.T) { t.Logf("Output: %s", out) t.Fatal(err) } - var exitFileList = [][]string{ + var existent = [][]string{ {dir, "subchart", "templates", "service.yaml"}, {dir, "subchart", "templates", "tests", "test-config.yaml"}, {dir, "subchart", "templates", "tests", "test-nothing.yaml"}, @@ -186,11 +186,11 @@ func TestTemplateOutputDir(t *testing.T) { {dir, "subchart", "charts", "subcharta", "templates", "service.yaml"}, {dir, "subchart", "charts", "subchartb", "templates", "service.yaml"}, } - for _, s := range exitFileList { + for _, s := range existent { _, err = os.Stat(filepath.Join(s...)) is.NoError(err) } - notExistFileList := [][]string{ + nonexistent := [][]string{ {dir, "hello", "templates", "empty"}, {dir, releaseName, "subchart", "templates", "service.yaml"}, {dir, releaseName, "subchart", "templates", "tests", "test-config.yaml"}, @@ -201,7 +201,7 @@ func TestTemplateOutputDir(t *testing.T) { {dir, releaseName, "subchart", "charts", "subcharta", "templates", "service.yaml"}, {dir, releaseName, "subchart", "charts", "subchartb", "templates", "service.yaml"}, } - for _, f := range notExistFileList { + for _, f := range nonexistent { _, err = os.Stat(filepath.Join(f...)) is.True(os.IsNotExist(err)) } @@ -216,14 +216,14 @@ func TestTemplateWithCRDsOutputDir(t *testing.T) { t.Logf("Output: %s", out) t.Fatal(err) } - var exitFileList = [][]string{ + var existent = [][]string{ {dir, "subchart", "crds", "crdA.yaml"}, } - for _, s := range exitFileList { + for _, s := range existent { _, err = os.Stat(filepath.Join(s...)) is.NoError(err) } - notExistFileList := [][]string{ + nonexistent := [][]string{ {dir, "hello", "templates", "empty"}, {dir, releaseName, "subchart", "templates", "service.yaml"}, {dir, releaseName, "subchart", "templates", "tests", "test-config.yaml"}, @@ -234,7 +234,7 @@ func TestTemplateWithCRDsOutputDir(t *testing.T) { {dir, releaseName, "subchart", "charts", "subcharta", "templates", "service.yaml"}, {dir, releaseName, "subchart", "charts", "subchartb", "templates", "service.yaml"}, } - for _, f := range notExistFileList { + for _, f := range nonexistent { _, err = os.Stat(filepath.Join(f...)) is.True(os.IsNotExist(err)) } @@ -249,7 +249,7 @@ func TestTemplateOutputDirWithReleaseName(t *testing.T) { t.Logf("Output: %s", out) t.Fatal(err) } - var exitFileList = [][]string{ + var existent = [][]string{ {dir, releaseName, "subchart", "templates", "service.yaml"}, {dir, releaseName, "subchart", "templates", "tests", "test-config.yaml"}, {dir, releaseName, "subchart", "templates", "tests", "test-nothing.yaml"}, @@ -259,11 +259,11 @@ func TestTemplateOutputDirWithReleaseName(t *testing.T) { {dir, releaseName, "subchart", "charts", "subcharta", "templates", "service.yaml"}, {dir, releaseName, "subchart", "charts", "subchartb", "templates", "service.yaml"}, } - for _, s := range exitFileList { + for _, s := range existent { _, err = os.Stat(filepath.Join(s...)) is.NoError(err) } - notExistFileList := [][]string{ + nonexistent := [][]string{ {dir, releaseName, "hello", "templates", "empty"}, {dir, "subchart", "templates", "service.yaml"}, {dir, "subchart", "templates", "tests", "test-config.yaml"}, @@ -274,7 +274,7 @@ func TestTemplateOutputDirWithReleaseName(t *testing.T) { {dir, "subchart", "charts", "subcharta", "templates", "service.yaml"}, {dir, "subchart", "charts", "subchartb", "templates", "service.yaml"}, } - for _, f := range notExistFileList { + for _, f := range nonexistent { _, err = os.Stat(filepath.Join(f...)) is.True(os.IsNotExist(err)) } @@ -289,11 +289,11 @@ func TestTemplateOutputDirSkiptest(t *testing.T) { t.Logf("Output: %s", out) t.Fatal(err) } - notExistFileList := [][]string{ + nonexistent := [][]string{ {dir, "subchart", "templates", "tests", "test-config.yaml"}, {dir, "subchart", "templates", "tests", "test-nothing.yaml"}, } - for _, f := range notExistFileList { + for _, f := range nonexistent { _, err = os.Stat(filepath.Join(f...)) is.True(os.IsNotExist(err)) }