From 75c4df0b56b84767cfe761a1eeea61909624f883 Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Wed, 9 May 2018 08:37:20 -0700 Subject: [PATCH] ref(tests): use golden files for testing command output --- Gopkg.lock | 8 +- cmd/helm/create_test.go | 8 +- cmd/helm/delete_test.go | 38 ++-- cmd/helm/dependency.go | 6 +- cmd/helm/dependency_build_test.go | 35 ++-- cmd/helm/dependency_test.go | 44 ++--- cmd/helm/dependency_update.go | 1 + cmd/helm/dependency_update_test.go | 50 +++--- cmd/helm/fetch_test.go | 66 +++---- cmd/helm/get_hooks_test.go | 25 ++- cmd/helm/get_manifest_test.go | 25 ++- cmd/helm/get_test.go | 25 ++- cmd/helm/get_values_test.go | 25 ++- cmd/helm/helm_test.go | 50 +++--- cmd/helm/history_test.go | 67 ++++--- cmd/helm/install_test.go | 73 ++++---- cmd/helm/list.go | 8 +- cmd/helm/list_test.go | 163 ++++++++--------- cmd/helm/package_test.go | 2 +- cmd/helm/release_testing_test.go | 83 ++++----- cmd/helm/repo_add_test.go | 24 +-- cmd/helm/repo_remove_test.go | 25 +-- cmd/helm/repo_update_test.go | 2 +- cmd/helm/rollback_test.go | 41 ++--- cmd/helm/search_test.go | 93 +++++----- cmd/helm/status_test.go | 166 +++++++----------- cmd/helm/testdata/output/delete-no-args.txt | 1 + cmd/helm/testdata/output/delete-no-hooks.txt | 1 + cmd/helm/testdata/output/delete-purge.txt | 1 + cmd/helm/testdata/output/delete-timeout.txt | 1 + cmd/helm/testdata/output/delete.txt | 1 + .../output/dependency-list-archive.txt | 4 + .../output/dependency-list-no-chart.txt | 1 + .../dependency-list-no-requirements.txt | 1 + cmd/helm/testdata/output/dependency-list.txt | 5 + .../testdata/output/get-hooks-no-args.txt | 1 + cmd/helm/testdata/output/get-hooks.txt | 7 + .../testdata/output/get-manifest-no-args.txt | 1 + cmd/helm/testdata/output/get-manifest.txt | 5 + cmd/helm/testdata/output/get-no-args.txt | 1 + cmd/helm/testdata/output/get-release.txt | 23 +++ cmd/helm/testdata/output/get-values-args.txt | 1 + cmd/helm/testdata/output/get-values.txt | 1 + cmd/helm/testdata/output/history-limit.txt | 3 + cmd/helm/testdata/output/history.json | 1 + cmd/helm/testdata/output/history.txt | 5 + cmd/helm/testdata/output/history.yaml | 11 ++ .../testdata/output/install-and-replace.txt | 5 + .../testdata/output/install-name-template.txt | 5 + cmd/helm/testdata/output/install-no-args.txt | 1 + cmd/helm/testdata/output/install-no-hooks.txt | 5 + .../install-with-multiple-values-files.txt | 5 + .../output/install-with-multiple-values.txt | 5 + .../testdata/output/install-with-timeout.txt | 5 + .../output/install-with-values-file.txt | 5 + .../testdata/output/install-with-values.txt | 5 + .../testdata/output/install-with-wait.txt | 5 + cmd/helm/testdata/output/install.txt | 5 + cmd/helm/testdata/output/list-with-failed.txt | 2 + .../list-with-mulitple-flags-deleting.txt | 2 + .../list-with-mulitple-flags-namespaced.txt | 2 + .../list-with-mulitple-flags-pending.txt | 2 + .../output/list-with-mulitple-flags.txt | 2 + .../output/list-with-mulitple-flags2.txt | 2 + .../testdata/output/list-with-namespace.txt | 2 + .../output/list-with-old-releases.txt | 3 + .../testdata/output/list-with-pending.txt | 4 + .../testdata/output/list-with-release.txt | 2 + cmd/helm/testdata/output/list.txt | 2 + cmd/helm/testdata/output/repo-add.txt | 1 + cmd/helm/testdata/output/rollback-no-args.txt | 1 + cmd/helm/testdata/output/rollback-timeout.txt | 1 + cmd/helm/testdata/output/rollback-wait.txt | 1 + cmd/helm/testdata/output/rollback.txt | 1 + .../output/search-constraint-single.txt | 2 + .../testdata/output/search-constraint.txt | 2 + .../search-multiple-versions-constraints.txt | 3 + .../output/search-multiple-versions.txt | 3 + cmd/helm/testdata/output/search-multiple.txt | 2 + cmd/helm/testdata/output/search-not-found.txt | 1 + cmd/helm/testdata/output/search-regex.txt | 2 + cmd/helm/testdata/output/search-single.txt | 2 + .../output/search-versions-constraint.txt | 2 + .../testdata/output/status-with-notes.txt | 6 + .../testdata/output/status-with-resource.txt | 8 + .../output/status-with-test-suite.txt | 11 ++ cmd/helm/testdata/output/status.json | 1 + cmd/helm/testdata/output/status.txt | 4 + cmd/helm/testdata/output/status.yaml | 9 + cmd/helm/testdata/output/test-error.txt | 2 + cmd/helm/testdata/output/test-failure.txt | 2 + cmd/helm/testdata/output/test-running.txt | 1 + cmd/helm/testdata/output/test-unknown.txt | 1 + cmd/helm/testdata/output/test.txt | 1 + .../output/upgrade-with-bad-dependencies.txt | 1 + .../output/upgrade-with-install-timeout.txt | 49 ++++++ .../testdata/output/upgrade-with-install.txt | 49 ++++++ .../upgrade-with-missing-dependencies.txt | 1 + .../output/upgrade-with-reset-values.txt | 49 ++++++ .../output/upgrade-with-reset-values2.txt | 49 ++++++ .../testdata/output/upgrade-with-timeout.txt | 49 ++++++ .../testdata/output/upgrade-with-wait.txt | 49 ++++++ cmd/helm/testdata/output/upgrade.txt | 49 ++++++ cmd/helm/testdata/output/version-template.txt | 1 + cmd/helm/testdata/output/version.txt | 1 + cmd/helm/testdata/testcache/foobar-index.yaml | 24 --- cmd/helm/testdata/testcache/local-index.yaml | 27 --- cmd/helm/upgrade_test.go | 74 ++++---- cmd/helm/verify_test.go | 81 ++++----- cmd/helm/version.go | 19 +- cmd/helm/version_test.go | 28 +-- internal/test/test.go | 88 ++++++++++ pkg/chartutil/capabilities.go | 2 +- pkg/hapi/chart/chart.go | 12 +- pkg/hapi/chart/metadata.go | 8 +- pkg/hapi/release/info.go | 4 +- pkg/hapi/tiller.go | 22 ++- pkg/helm/fake.go | 8 +- pkg/helm/helm_test.go | 4 +- pkg/helm/option.go | 4 +- pkg/lint/rules/chartfile.go | 4 +- pkg/tiller/release_list.go | 6 +- pkg/tiller/release_list_test.go | 4 +- pkg/urlutil/urlutil_test.go | 2 +- pkg/version/version.go | 5 +- pkg/version/version_test.go | 5 +- 126 files changed, 1301 insertions(+), 852 deletions(-) create mode 100644 cmd/helm/testdata/output/delete-no-args.txt create mode 100644 cmd/helm/testdata/output/delete-no-hooks.txt create mode 100644 cmd/helm/testdata/output/delete-purge.txt create mode 100644 cmd/helm/testdata/output/delete-timeout.txt create mode 100644 cmd/helm/testdata/output/delete.txt create mode 100644 cmd/helm/testdata/output/dependency-list-archive.txt create mode 100644 cmd/helm/testdata/output/dependency-list-no-chart.txt create mode 100644 cmd/helm/testdata/output/dependency-list-no-requirements.txt create mode 100644 cmd/helm/testdata/output/dependency-list.txt create mode 100644 cmd/helm/testdata/output/get-hooks-no-args.txt create mode 100644 cmd/helm/testdata/output/get-hooks.txt create mode 100644 cmd/helm/testdata/output/get-manifest-no-args.txt create mode 100644 cmd/helm/testdata/output/get-manifest.txt create mode 100644 cmd/helm/testdata/output/get-no-args.txt create mode 100644 cmd/helm/testdata/output/get-release.txt create mode 100644 cmd/helm/testdata/output/get-values-args.txt create mode 100644 cmd/helm/testdata/output/get-values.txt create mode 100644 cmd/helm/testdata/output/history-limit.txt create mode 100644 cmd/helm/testdata/output/history.json create mode 100644 cmd/helm/testdata/output/history.txt create mode 100644 cmd/helm/testdata/output/history.yaml create mode 100644 cmd/helm/testdata/output/install-and-replace.txt create mode 100644 cmd/helm/testdata/output/install-name-template.txt create mode 100644 cmd/helm/testdata/output/install-no-args.txt create mode 100644 cmd/helm/testdata/output/install-no-hooks.txt create mode 100644 cmd/helm/testdata/output/install-with-multiple-values-files.txt create mode 100644 cmd/helm/testdata/output/install-with-multiple-values.txt create mode 100644 cmd/helm/testdata/output/install-with-timeout.txt create mode 100644 cmd/helm/testdata/output/install-with-values-file.txt create mode 100644 cmd/helm/testdata/output/install-with-values.txt create mode 100644 cmd/helm/testdata/output/install-with-wait.txt create mode 100644 cmd/helm/testdata/output/install.txt create mode 100644 cmd/helm/testdata/output/list-with-failed.txt create mode 100644 cmd/helm/testdata/output/list-with-mulitple-flags-deleting.txt create mode 100644 cmd/helm/testdata/output/list-with-mulitple-flags-namespaced.txt create mode 100644 cmd/helm/testdata/output/list-with-mulitple-flags-pending.txt create mode 100644 cmd/helm/testdata/output/list-with-mulitple-flags.txt create mode 100644 cmd/helm/testdata/output/list-with-mulitple-flags2.txt create mode 100644 cmd/helm/testdata/output/list-with-namespace.txt create mode 100644 cmd/helm/testdata/output/list-with-old-releases.txt create mode 100644 cmd/helm/testdata/output/list-with-pending.txt create mode 100644 cmd/helm/testdata/output/list-with-release.txt create mode 100644 cmd/helm/testdata/output/list.txt create mode 100644 cmd/helm/testdata/output/repo-add.txt create mode 100644 cmd/helm/testdata/output/rollback-no-args.txt create mode 100644 cmd/helm/testdata/output/rollback-timeout.txt create mode 100644 cmd/helm/testdata/output/rollback-wait.txt create mode 100644 cmd/helm/testdata/output/rollback.txt create mode 100644 cmd/helm/testdata/output/search-constraint-single.txt create mode 100644 cmd/helm/testdata/output/search-constraint.txt create mode 100644 cmd/helm/testdata/output/search-multiple-versions-constraints.txt create mode 100644 cmd/helm/testdata/output/search-multiple-versions.txt create mode 100644 cmd/helm/testdata/output/search-multiple.txt create mode 100644 cmd/helm/testdata/output/search-not-found.txt create mode 100644 cmd/helm/testdata/output/search-regex.txt create mode 100644 cmd/helm/testdata/output/search-single.txt create mode 100644 cmd/helm/testdata/output/search-versions-constraint.txt create mode 100644 cmd/helm/testdata/output/status-with-notes.txt create mode 100644 cmd/helm/testdata/output/status-with-resource.txt create mode 100644 cmd/helm/testdata/output/status-with-test-suite.txt create mode 100644 cmd/helm/testdata/output/status.json create mode 100644 cmd/helm/testdata/output/status.txt create mode 100644 cmd/helm/testdata/output/status.yaml create mode 100644 cmd/helm/testdata/output/test-error.txt create mode 100644 cmd/helm/testdata/output/test-failure.txt create mode 100644 cmd/helm/testdata/output/test-running.txt create mode 100644 cmd/helm/testdata/output/test-unknown.txt create mode 100644 cmd/helm/testdata/output/test.txt create mode 100644 cmd/helm/testdata/output/upgrade-with-bad-dependencies.txt create mode 100644 cmd/helm/testdata/output/upgrade-with-install-timeout.txt create mode 100644 cmd/helm/testdata/output/upgrade-with-install.txt create mode 100644 cmd/helm/testdata/output/upgrade-with-missing-dependencies.txt create mode 100644 cmd/helm/testdata/output/upgrade-with-reset-values.txt create mode 100644 cmd/helm/testdata/output/upgrade-with-reset-values2.txt create mode 100644 cmd/helm/testdata/output/upgrade-with-timeout.txt create mode 100644 cmd/helm/testdata/output/upgrade-with-wait.txt create mode 100644 cmd/helm/testdata/output/upgrade.txt create mode 100644 cmd/helm/testdata/output/version-template.txt create mode 100644 cmd/helm/testdata/output/version.txt delete mode 100644 cmd/helm/testdata/testcache/foobar-index.yaml delete mode 100644 cmd/helm/testdata/testcache/local-index.yaml create mode 100644 internal/test/test.go diff --git a/Gopkg.lock b/Gopkg.lock index 9eb933fef..3ef21b868 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -384,6 +384,12 @@ revision = "5f041e8faa004a95c88a202771f4cc3e991971e6" version = "v2.0.1" +[[projects]] + name = "github.com/pkg/errors" + packages = ["."] + revision = "645ef00459ed84a119197bfb8d8205042c6df63d" + version = "v0.8.0" + [[projects]] name = "github.com/pmezard/go-difflib" packages = ["difflib"] @@ -1071,6 +1077,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "82526354be9627a0e3796098ee9bed433a3e7958495f65e371ecc27d8c71c111" + inputs-digest = "4a0464d8de132c8a733f50549ad69e663b992e12537b58626302dc5dd14cd3f0" solver-name = "gps-cdcl" solver-version = 1 diff --git a/cmd/helm/create_test.go b/cmd/helm/create_test.go index 380b6d8cb..bf3fdc342 100644 --- a/cmd/helm/create_test.go +++ b/cmd/helm/create_test.go @@ -17,6 +17,7 @@ limitations under the License. package main import ( + "fmt" "io/ioutil" "os" "path/filepath" @@ -46,8 +47,7 @@ func TestCreateCmd(t *testing.T) { defer os.Chdir(pwd) // Run a create - cmd := newCreateCmd(ioutil.Discard) - if err := cmd.RunE(cmd, []string{cname}); err != nil { + if _, err := executeCommand(nil, "create "+cname); err != nil { t.Errorf("Failed to run create: %s", err) return } @@ -117,9 +117,7 @@ func TestCreateStarterCmd(t *testing.T) { defer os.Chdir(pwd) // Run a create - cmd := newCreateCmd(ioutil.Discard) - cmd.ParseFlags([]string{"--starter", "starterchart"}) - if err := cmd.RunE(cmd, []string{cname}); err != nil { + if _, err := executeCommand(nil, fmt.Sprintf("--home=%s create --starter=starterchart %s", thome, cname)); err != nil { t.Errorf("Failed to run create: %s", err) return } diff --git a/cmd/helm/delete_test.go b/cmd/helm/delete_test.go index 035b9d775..fffaccdd6 100644 --- a/cmd/helm/delete_test.go +++ b/cmd/helm/delete_test.go @@ -25,41 +25,37 @@ import ( func TestDelete(t *testing.T) { - resp := helm.ReleaseMock(&helm.MockReleaseOptions{Name: "aeneas"}) rels := []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "aeneas"})} tests := []releaseCase{ { - name: "basic delete", - cmd: "delete aeneas", - matches: `release "aeneas" deleted`, - resp: resp, - rels: rels, + name: "basic delete", + cmd: "delete aeneas", + golden: "output/delete.txt", + rels: rels, }, { - name: "delete with timeout", - cmd: "delete aeneas --timeout 120", - matches: `release "aeneas" deleted`, - resp: resp, - rels: rels, + name: "delete with timeout", + cmd: "delete aeneas --timeout 120", + golden: "output/delete-timeout.txt", + rels: rels, }, { - name: "delete without hooks", - cmd: "delete aeneas --no-hooks", - matches: `release "aeneas" deleted`, - resp: resp, - rels: rels, + name: "delete without hooks", + cmd: "delete aeneas --no-hooks", + golden: "output/delete-no-hooks.txt", + rels: rels, }, { - name: "purge", - cmd: "delete aeneas --purge", - matches: `release "aeneas" deleted`, - resp: resp, - rels: rels, + name: "purge", + cmd: "delete aeneas --purge", + golden: "output/delete-purge.txt", + rels: rels, }, { name: "delete without release", cmd: "delete", + golden: "output/delete-no-args.txt", wantError: true, }, } diff --git a/cmd/helm/dependency.go b/cmd/helm/dependency.go index 231659691..b3ce2d064 100644 --- a/cmd/helm/dependency.go +++ b/cmd/helm/dependency.go @@ -121,11 +121,7 @@ func newDependencyListCmd(out io.Writer) *cobra.Command { cp = args[0] } - var err error - dlc.chartpath, err = filepath.Abs(cp) - if err != nil { - return err - } + dlc.chartpath = filepath.Clean(cp) return dlc.run() }, } diff --git a/cmd/helm/dependency_build_test.go b/cmd/helm/dependency_build_test.go index 2d7c88654..b313f5c2c 100644 --- a/cmd/helm/dependency_build_test.go +++ b/cmd/helm/dependency_build_test.go @@ -16,13 +16,11 @@ limitations under the License. package main import ( - "bytes" + "fmt" "os" - "path/filepath" "strings" "testing" - "k8s.io/helm/pkg/helm/helmpath" "k8s.io/helm/pkg/provenance" "k8s.io/helm/pkg/repo" "k8s.io/helm/pkg/repo/repotest" @@ -53,32 +51,28 @@ func TestDependencyBuildCmd(t *testing.T) { t.Fatal(err) } - out := bytes.NewBuffer(nil) - dbc := &dependencyBuildCmd{out: out} - dbc.helmhome = helmpath.Home(hh) - dbc.chartpath = filepath.Join(hh.String(), chartname) + cmd := fmt.Sprintf("--home=%s dependency build %s", hh, hh.Path(chartname)) + out, err := executeCommand(nil, cmd) // In the first pass, we basically want the same results as an update. - if err := dbc.run(); err != nil { - output := out.String() - t.Logf("Output: %s", output) + if err != nil { + t.Logf("Output: %s", out) t.Fatal(err) } - output := out.String() - if !strings.Contains(output, `update from the "test" chart repository`) { - t.Errorf("Repo did not get updated\n%s", output) + if !strings.Contains(out, `update from the "test" chart repository`) { + t.Errorf("Repo did not get updated\n%s", out) } // Make sure the actual file got downloaded. - expect := filepath.Join(hh.String(), chartname, "charts/reqtest-0.1.0.tgz") + expect := hh.Path(chartname, "charts/reqtest-0.1.0.tgz") if _, err := os.Stat(expect); err != nil { t.Fatal(err) } // In the second pass, we want to remove the chart's request dependency, // then see if it restores from the lock. - lockfile := filepath.Join(hh.String(), chartname, "requirements.lock") + lockfile := hh.Path(chartname, "requirements.lock") if _, err := os.Stat(lockfile); err != nil { t.Fatal(err) } @@ -86,14 +80,14 @@ func TestDependencyBuildCmd(t *testing.T) { t.Fatal(err) } - if err := dbc.run(); err != nil { - output := out.String() - t.Logf("Output: %s", output) + out, err = executeCommand(nil, cmd) + if err != nil { + t.Logf("Output: %s", out) t.Fatal(err) } // Now repeat the test that the dependency exists. - expect = filepath.Join(hh.String(), chartname, "charts/reqtest-0.1.0.tgz") + expect = hh.Path(chartname, "charts/reqtest-0.1.0.tgz") if _, err := os.Stat(expect); err != nil { t.Fatal(err) } @@ -104,7 +98,7 @@ func TestDependencyBuildCmd(t *testing.T) { t.Fatal(err) } - i, err := repo.LoadIndexFile(dbc.helmhome.CacheIndex("test")) + i, err := repo.LoadIndexFile(hh.CacheIndex("test")) if err != nil { t.Fatal(err) } @@ -116,5 +110,4 @@ func TestDependencyBuildCmd(t *testing.T) { if v := reqver.Version; v != "0.1.0" { t.Errorf("mismatched versions. Expected %q, got %q", "0.1.0", v) } - } diff --git a/cmd/helm/dependency_test.go b/cmd/helm/dependency_test.go index 7d56e1d75..27e64f28b 100644 --- a/cmd/helm/dependency_test.go +++ b/cmd/helm/dependency_test.go @@ -20,31 +20,23 @@ import ( ) func TestDependencyListCmd(t *testing.T) { - - tests := []releaseCase{ - { - name: "No such chart", - cmd: "dependency list /no/such/chart", - wantError: true, - }, - { - name: "No requirements.yaml", - cmd: "dependency list testdata/testcharts/alpine", - matches: "WARNING: no requirements at ", - }, - { - name: "Requirements in chart dir", - cmd: "dependency list testdata/testcharts/reqtest", - matches: "NAME \tVERSION\tREPOSITORY \tSTATUS \n" + - "reqsubchart \t0.1.0 \thttps://example.com/charts\tunpacked\n" + - "reqsubchart2\t0.2.0 \thttps://example.com/charts\tunpacked\n" + - "reqsubchart3\t>=0.1.0\thttps://example.com/charts\tok \n\n", - }, - { - name: "Requirements in chart archive", - cmd: "dependency list testdata/testcharts/reqtest-0.1.0.tgz", - matches: "NAME \tVERSION\tREPOSITORY \tSTATUS \nreqsubchart \t0.1.0 \thttps://example.com/charts\tmissing\nreqsubchart2\t0.2.0 \thttps://example.com/charts\tmissing\n", - }, - } + tests := []releaseCase{{ + name: "No such chart", + cmd: "dependency list /no/such/chart", + golden: "output/dependency-list-no-chart.txt", + wantError: true, + }, { + name: "No requirements.yaml", + cmd: "dependency list testdata/testcharts/alpine", + golden: "output/dependency-list-no-requirements.txt", + }, { + name: "Requirements in chart dir", + cmd: "dependency list testdata/testcharts/reqtest", + golden: "output/dependency-list.txt", + }, { + name: "Requirements in chart archive", + cmd: "dependency list testdata/testcharts/reqtest-0.1.0.tgz", + golden: "output/dependency-list-archive.txt", + }} testReleaseCmd(t, tests) } diff --git a/cmd/helm/dependency_update.go b/cmd/helm/dependency_update.go index d6a998639..20708fb5f 100644 --- a/cmd/helm/dependency_update.go +++ b/cmd/helm/dependency_update.go @@ -20,6 +20,7 @@ import ( "path/filepath" "github.com/spf13/cobra" + "k8s.io/helm/pkg/downloader" "k8s.io/helm/pkg/getter" "k8s.io/helm/pkg/helm/helmpath" diff --git a/cmd/helm/dependency_update_test.go b/cmd/helm/dependency_update_test.go index 6adc08391..71292b4e7 100644 --- a/cmd/helm/dependency_update_test.go +++ b/cmd/helm/dependency_update_test.go @@ -17,6 +17,7 @@ package main import ( "bytes" + "fmt" "io/ioutil" "os" "path/filepath" @@ -60,25 +61,19 @@ func TestDependencyUpdateCmd(t *testing.T) { t.Fatal(err) } - out := bytes.NewBuffer(nil) - duc := &dependencyUpdateCmd{out: out} - duc.helmhome = helmpath.Home(hh) - duc.chartpath = filepath.Join(hh.String(), chartname) - - if err := duc.run(); err != nil { - output := out.String() - t.Logf("Output: %s", output) + out, err := executeCommand(nil, fmt.Sprintf("--home=%s dependency update %s", hh, hh.Path(chartname))) + if err != nil { + t.Logf("Output: %s", out) t.Fatal(err) } - output := out.String() // This is written directly to stdout, so we have to capture as is. - if !strings.Contains(output, `update from the "test" chart repository`) { - t.Errorf("Repo did not get updated\n%s", output) + if !strings.Contains(out, `update from the "test" chart repository`) { + t.Errorf("Repo did not get updated\n%s", out) } // Make sure the actual file got downloaded. - expect := filepath.Join(hh.String(), chartname, "charts/reqtest-0.1.0.tgz") + expect := hh.Path(chartname, "charts/reqtest-0.1.0.tgz") if _, err := os.Stat(expect); err != nil { t.Fatal(err) } @@ -88,7 +83,7 @@ func TestDependencyUpdateCmd(t *testing.T) { t.Fatal(err) } - i, err := repo.LoadIndexFile(duc.helmhome.CacheIndex("test")) + i, err := repo.LoadIndexFile(hh.CacheIndex("test")) if err != nil { t.Fatal(err) } @@ -106,23 +101,24 @@ func TestDependencyUpdateCmd(t *testing.T) { {Name: "compressedchart", Version: "0.3.0", Repository: srv.URL()}, }, } - dir := filepath.Join(hh.String(), chartname) + dir := hh.Path(chartname) if err := writeRequirements(dir, reqfile); err != nil { t.Fatal(err) } - if err := duc.run(); err != nil { - output := out.String() - t.Logf("Output: %s", output) + + out, err = executeCommand(nil, fmt.Sprintf("--home=%s dependency update %s", hh, hh.Path(chartname))) + if err != nil { + t.Logf("Output: %s", out) t.Fatal(err) } // In this second run, we should see compressedchart-0.3.0.tgz, and not // the 0.1.0 version. - expect = filepath.Join(hh.String(), chartname, "charts/compressedchart-0.3.0.tgz") + expect = hh.Path(chartname, "charts/compressedchart-0.3.0.tgz") if _, err := os.Stat(expect); err != nil { t.Fatalf("Expected %q: %s", expect, err) } - dontExpect := filepath.Join(hh.String(), chartname, "charts/compressedchart-0.1.0.tgz") + dontExpect := hh.Path(chartname, "charts/compressedchart-0.1.0.tgz") if _, err := os.Stat(dontExpect); err == nil { t.Fatalf("Unexpected %q", dontExpect) } @@ -155,20 +151,14 @@ func TestDependencyUpdateCmd_SkipRefresh(t *testing.T) { t.Fatal(err) } - out := bytes.NewBuffer(nil) - duc := &dependencyUpdateCmd{out: out} - duc.helmhome = helmpath.Home(hh) - duc.chartpath = filepath.Join(hh.String(), chartname) - duc.skipRefresh = true - - if err := duc.run(); err == nil { + out, err := executeCommand(nil, fmt.Sprintf("--home=%s dependency update --skip-refresh %s", hh, hh.Path(chartname))) + if err == nil { t.Fatal("Expected failure to find the repo with skipRefresh") } - output := out.String() // This is written directly to stdout, so we have to capture as is. - if strings.Contains(output, `update from the "test" chart repository`) { - t.Errorf("Repo was unexpectedly updated\n%s", output) + if strings.Contains(out, `update from the "test" chart repository`) { + t.Errorf("Repo was unexpectedly updated\n%s", out) } } @@ -202,7 +192,7 @@ func TestDependencyUpdateCmd_DontDeleteOldChartsOnError(t *testing.T) { out := bytes.NewBuffer(nil) duc := &dependencyUpdateCmd{out: out} duc.helmhome = helmpath.Home(hh) - duc.chartpath = filepath.Join(hh.String(), chartname) + duc.chartpath = hh.Path(chartname) if err := duc.run(); err != nil { output := out.String() diff --git a/cmd/helm/fetch_test.go b/cmd/helm/fetch_test.go index 13247ee99..66b688a41 100644 --- a/cmd/helm/fetch_test.go +++ b/cmd/helm/fetch_test.go @@ -17,11 +17,11 @@ limitations under the License. package main import ( - "bytes" "fmt" "os" "path/filepath" "regexp" + "strings" "testing" "k8s.io/helm/pkg/repo/repotest" @@ -45,9 +45,8 @@ func TestFetchCmd(t *testing.T) { // all flags will get "--home=TMDIR -d outdir" appended. tests := []struct { name string - chart string - flags []string - fail bool + args []string + wantError bool failExpect string expectFile string expectDir bool @@ -55,82 +54,72 @@ func TestFetchCmd(t *testing.T) { }{ { name: "Basic chart fetch", - chart: "test/signtest", + args: []string{"test/signtest"}, expectFile: "./signtest-0.1.0.tgz", }, { name: "Chart fetch with version", - chart: "test/signtest", - flags: []string{"--version", "0.1.0"}, + args: []string{"test/signtest --version=0.1.0"}, expectFile: "./signtest-0.1.0.tgz", }, { name: "Fail chart fetch with non-existent version", - chart: "test/signtest", - flags: []string{"--version", "99.1.0"}, - fail: true, + args: []string{"test/signtest --version=99.1.0"}, + wantError: true, failExpect: "no such chart", }, { name: "Fail fetching non-existent chart", - chart: "test/nosuchthing", + args: []string{"test/nosuchthing"}, failExpect: "Failed to fetch", - fail: true, + wantError: true, }, { name: "Fetch and verify", - chart: "test/signtest", - flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub"}, + args: []string{"test/signtest --verify --keyring testdata/helm-test-key.pub"}, expectFile: "./signtest-0.1.0.tgz", expectVerify: true, }, { name: "Fetch and fail verify", - chart: "test/reqtest", - flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub"}, + args: []string{"test/reqtest --verify --keyring testdata/helm-test-key.pub"}, failExpect: "Failed to fetch provenance", - fail: true, + wantError: true, }, { name: "Fetch and untar", - chart: "test/signtest", - flags: []string{"--untar", "--untardir", "signtest"}, + args: []string{"test/signtest --untar --untardir signtest"}, expectFile: "./signtest", expectDir: true, }, { name: "Fetch, verify, untar", - chart: "test/signtest", - flags: []string{"--verify", "--keyring", "testdata/helm-test-key.pub", "--untar", "--untardir", "signtest"}, + args: []string{"test/signtest --verify --keyring=testdata/helm-test-key.pub --untar --untardir signtest"}, expectFile: "./signtest", expectDir: true, expectVerify: true, }, { name: "Chart fetch using repo URL", - chart: "signtest", expectFile: "./signtest-0.1.0.tgz", - flags: []string{"--repo", srv.URL()}, + args: []string{"signtest --repo", srv.URL()}, }, { name: "Fail fetching non-existent chart on repo URL", - chart: "someChart", - flags: []string{"--repo", srv.URL()}, + args: []string{"someChart --repo", srv.URL()}, failExpect: "Failed to fetch chart", - fail: true, + wantError: true, }, { name: "Specific version chart fetch using repo URL", - chart: "signtest", expectFile: "./signtest-0.1.0.tgz", - flags: []string{"--repo", srv.URL(), "--version", "0.1.0"}, + args: []string{"signtest --version=0.1.0 --repo", srv.URL()}, }, { name: "Specific version chart fetch using repo URL", - chart: "signtest", - flags: []string{"--repo", srv.URL(), "--version", "0.2.0"}, + args: []string{"signtest --version=0.2.0 --repo", srv.URL()}, failExpect: "Failed to fetch chart version", - fail: true, + wantError: true, }, } @@ -146,24 +135,23 @@ func TestFetchCmd(t *testing.T) { os.RemoveAll(outdir) os.Mkdir(outdir, 0755) - buf := bytes.NewBuffer(nil) - cmd := newFetchCmd(buf) - tt.flags = append(tt.flags, "-d", outdir) - cmd.ParseFlags(tt.flags) - if err := cmd.RunE(cmd, []string{tt.chart}); err != nil { - if tt.fail { + cmd := strings.Join(append(tt.args, "-d", outdir, "--home", hh.String()), " ") + out, err := executeCommand(nil, "fetch "+cmd) + if err != nil { + if tt.wantError { continue } t.Errorf("%q reported error: %s", tt.name, err) continue } + if tt.expectVerify { pointerAddressPattern := "0[xX][A-Fa-f0-9]+" sha256Pattern := "[A-Fa-f0-9]{64}" verificationRegex := regexp.MustCompile( fmt.Sprintf("Verification: &{%s sha256:%s signtest-0.1.0.tgz}\n", pointerAddressPattern, sha256Pattern)) - if !verificationRegex.MatchString(buf.String()) { - t.Errorf("%q: expected match for regex %s, got %s", tt.name, verificationRegex, buf.String()) + if !verificationRegex.MatchString(out) { + t.Errorf("%q: expected match for regex %s, got %s", tt.name, verificationRegex, out) } } diff --git a/cmd/helm/get_hooks_test.go b/cmd/helm/get_hooks_test.go index c9d5bdb1b..1af2fdbd3 100644 --- a/cmd/helm/get_hooks_test.go +++ b/cmd/helm/get_hooks_test.go @@ -24,19 +24,16 @@ import ( ) func TestGetHooks(t *testing.T) { - tests := []releaseCase{ - { - name: "get hooks with release", - cmd: "get hooks aeneas", - matches: helm.MockHookTemplate, - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "aeneas"}), - rels: []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "aeneas"})}, - }, - { - name: "get hooks without args", - cmd: "get hooks", - wantError: true, - }, - } + tests := []releaseCase{{ + name: "get hooks with release", + cmd: "get hooks aeneas", + golden: "output/get-hooks.txt", + rels: []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "aeneas"})}, + }, { + name: "get hooks without args", + cmd: "get hooks", + golden: "output/get-hooks-no-args.txt", + wantError: true, + }} testReleaseCmd(t, tests) } diff --git a/cmd/helm/get_manifest_test.go b/cmd/helm/get_manifest_test.go index c668826ca..08160a71b 100644 --- a/cmd/helm/get_manifest_test.go +++ b/cmd/helm/get_manifest_test.go @@ -24,19 +24,16 @@ import ( ) func TestGetManifest(t *testing.T) { - tests := []releaseCase{ - { - name: "get manifest with release", - cmd: "get manifest juno", - matches: helm.MockManifest, - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "juno"}), - rels: []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "juno"})}, - }, - { - name: "get manifest without args", - cmd: "get manifest", - wantError: true, - }, - } + tests := []releaseCase{{ + name: "get manifest with release", + cmd: "get manifest juno", + golden: "output/get-manifest.txt", + rels: []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "juno"})}, + }, { + name: "get manifest without args", + cmd: "get manifest", + golden: "output/get-manifest-no-args.txt", + wantError: true, + }} testReleaseCmd(t, tests) } diff --git a/cmd/helm/get_test.go b/cmd/helm/get_test.go index f1b66992b..9a00bb356 100644 --- a/cmd/helm/get_test.go +++ b/cmd/helm/get_test.go @@ -24,19 +24,16 @@ import ( ) func TestGetCmd(t *testing.T) { - tests := []releaseCase{ - { - name: "get with a release", - cmd: "get thomas-guide", - matches: "REVISION: 1\nRELEASED: (.*)\nCHART: foo-0.1.0-beta.1\nUSER-SUPPLIED VALUES:\nname: \"value\"\nCOMPUTED VALUES:\nname: value\n\nHOOKS:\n---\n# pre-install-hook\n" + helm.MockHookTemplate + "\nMANIFEST:", - rels: []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"})}, - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}), - }, - { - name: "get requires release name arg", - cmd: "get", - wantError: true, - }, - } + tests := []releaseCase{{ + name: "get with a release", + cmd: "get thomas-guide", + golden: "output/get-release.txt", + rels: []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"})}, + }, { + name: "get requires release name arg", + cmd: "get", + golden: "output/get-no-args.txt", + wantError: true, + }} testReleaseCmd(t, tests) } diff --git a/cmd/helm/get_values_test.go b/cmd/helm/get_values_test.go index 63b637ba3..bcef9c432 100644 --- a/cmd/helm/get_values_test.go +++ b/cmd/helm/get_values_test.go @@ -24,19 +24,16 @@ import ( ) func TestGetValuesCmd(t *testing.T) { - tests := []releaseCase{ - { - name: "get values with a release", - cmd: "get values thomas-guide", - matches: "name: \"value\"", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}), - rels: []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"})}, - }, - { - name: "get values requires release name arg", - cmd: "get values", - wantError: true, - }, - } + tests := []releaseCase{{ + name: "get values with a release", + cmd: "get values thomas-guide", + golden: "output/get-values.txt", + rels: []*release.Release{helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"})}, + }, { + name: "get values requires release name arg", + cmd: "get values", + golden: "output/get-values-args.txt", + wantError: true, + }} testReleaseCmd(t, tests) } diff --git a/cmd/helm/helm_test.go b/cmd/helm/helm_test.go index 098c9be26..102e4054b 100644 --- a/cmd/helm/helm_test.go +++ b/cmd/helm/helm_test.go @@ -22,13 +22,13 @@ import ( "io/ioutil" "os" "path/filepath" - "regexp" "strings" "testing" shellwords "github.com/mattn/go-shellwords" "github.com/spf13/cobra" + "k8s.io/helm/internal/test" "k8s.io/helm/pkg/hapi/release" "k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm/helmpath" @@ -56,19 +56,19 @@ func executeCommandC(client helm.Interface, cmd string) (*cobra.Command, string, } func testReleaseCmd(t *testing.T, tests []releaseCase) { + t.Helper() for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := &helm.FakeClient{ - Rels: tt.rels, - Responses: tt.responses, + Rels: tt.rels, + TestRunStatus: tt.testRunStatus, } out, err := executeCommand(c, tt.cmd) if (err != nil) != tt.wantError { t.Errorf("expected error, got '%v'", err) } - re := regexp.MustCompile(tt.matches) - if !re.MatchString(out) { - t.Errorf("expected\n%q\ngot\n%q", tt.matches, out) + if tt.golden != "" { + test.AssertGoldenString(t, out, tt.golden) } }) } @@ -76,15 +76,13 @@ func testReleaseCmd(t *testing.T, tests []releaseCase) { // releaseCase describes a test case that works with releases. type releaseCase struct { - name string - cmd string - // matches is the string to be matched. This supports regular expressions. - matches string + name string + cmd string + golden string wantError bool - resp *release.Release // Rels are the available releases at the start of the test. - rels []*release.Release - responses map[string]release.TestRunStatus + rels []*release.Release + testRunStatus map[string]release.TestRunStatus } // tempHelmHome sets up a Helm Home in a temp dir. @@ -99,7 +97,7 @@ func tempHelmHome(t *testing.T) (helmpath.Home, error) { } settings.Home = helmpath.Home(dir) - if err := ensureTestHome(settings.Home, t); err != nil { + if err := ensureTestHome(t, settings.Home); err != nil { return helmpath.Home("n/"), err } settings.Home = oldhome @@ -109,20 +107,22 @@ func tempHelmHome(t *testing.T) (helmpath.Home, error) { // ensureTestHome creates a home directory like ensureHome, but without remote references. // // t is used only for logging. -func ensureTestHome(home helmpath.Home, t *testing.T) error { - configDirectories := []string{home.String(), home.Repository(), home.Cache(), home.Plugins(), home.Starters()} - for _, p := range configDirectories { - if fi, err := os.Stat(p); err != nil { - if err := os.MkdirAll(p, 0755); err != nil { - return fmt.Errorf("Could not create %s: %s", p, err) - } - } else if !fi.IsDir() { - return fmt.Errorf("%s must be a directory", p) +func ensureTestHome(t *testing.T, home helmpath.Home) error { + t.Helper() + for _, p := range []string{ + home.String(), + home.Repository(), + home.Cache(), + home.Plugins(), + home.Starters(), + } { + if err := os.MkdirAll(p, 0755); err != nil { + return fmt.Errorf("Could not create %s: %s", p, err) } } repoFile := home.RepositoryFile() - if fi, err := os.Stat(repoFile); err != nil { + if _, err := os.Stat(repoFile); err != nil { rf := repo.NewRepoFile() rf.Add(&repo.Entry{ Name: "charts", @@ -132,8 +132,6 @@ func ensureTestHome(home helmpath.Home, t *testing.T) error { if err := rf.WriteFile(repoFile, 0644); err != nil { return err } - } else if fi.IsDir() { - return fmt.Errorf("%s must be a file, not a directory", repoFile) } if r, err := repo.LoadRepositoriesFile(repoFile); err == repo.ErrRepoOutOfDate { t.Log("Updating repository file format...") diff --git a/cmd/helm/history_test.go b/cmd/helm/history_test.go index 780b00d25..84fcfe691 100644 --- a/cmd/helm/history_test.go +++ b/cmd/helm/history_test.go @@ -32,45 +32,40 @@ func TestHistoryCmd(t *testing.T) { }) } - tests := []releaseCase{ - { - name: "get history for release", - cmd: "history angry-bird", - rels: []*rpb.Release{ - mk("angry-bird", 4, rpb.StatusDeployed), - mk("angry-bird", 3, rpb.StatusSuperseded), - mk("angry-bird", 2, rpb.StatusSuperseded), - mk("angry-bird", 1, rpb.StatusSuperseded), - }, - matches: `REVISION\s+UPDATED\s+STATUS\s+CHART\s+DESCRIPTION \n1\s+(.*)\s+superseded\s+foo-0.1.0-beta.1\s+Release mock\n2(.*)superseded\s+foo-0.1.0-beta.1\s+Release mock\n3(.*)superseded\s+foo-0.1.0-beta.1\s+Release mock\n4(.*)deployed\s+foo-0.1.0-beta.1\s+Release mock\n`, + tests := []releaseCase{{ + name: "get history for release", + cmd: "history angry-bird", + rels: []*rpb.Release{ + mk("angry-bird", 4, rpb.StatusDeployed), + mk("angry-bird", 3, rpb.StatusSuperseded), + mk("angry-bird", 2, rpb.StatusSuperseded), + mk("angry-bird", 1, rpb.StatusSuperseded), }, - { - name: "get history with max limit set", - cmd: "history angry-bird --max 2", - rels: []*rpb.Release{ - mk("angry-bird", 4, rpb.StatusDeployed), - mk("angry-bird", 3, rpb.StatusSuperseded), - }, - matches: `REVISION\s+UPDATED\s+STATUS\s+CHART\s+DESCRIPTION \n3\s+(.*)\s+superseded\s+foo-0.1.0-beta.1\s+Release mock\n4\s+(.*)\s+deployed\s+foo-0.1.0-beta.1\s+Release mock\n`, + golden: "output/history.txt", + }, { + name: "get history with max limit set", + cmd: "history angry-bird --max 2", + rels: []*rpb.Release{ + mk("angry-bird", 4, rpb.StatusDeployed), + mk("angry-bird", 3, rpb.StatusSuperseded), }, - { - name: "get history with yaml output format", - cmd: "history angry-bird --output yaml", - rels: []*rpb.Release{ - mk("angry-bird", 4, rpb.StatusDeployed), - mk("angry-bird", 3, rpb.StatusSuperseded), - }, - matches: "- chart: foo-0.1.0-beta.1\n description: Release mock\n revision: 3\n status: superseded\n updated: (.*)\n- chart: foo-0.1.0-beta.1\n description: Release mock\n revision: 4\n status: deployed\n updated: (.*)\n\n", + golden: "output/history-limit.txt", + }, { + name: "get history with yaml output format", + cmd: "history angry-bird --output yaml", + rels: []*rpb.Release{ + mk("angry-bird", 4, rpb.StatusDeployed), + mk("angry-bird", 3, rpb.StatusSuperseded), }, - { - name: "get history with json output format", - cmd: "history angry-bird --output json", - rels: []*rpb.Release{ - mk("angry-bird", 4, rpb.StatusDeployed), - mk("angry-bird", 3, rpb.StatusSuperseded), - }, - matches: `[{"revision":3,"updated":".*","status":"superseded","chart":"foo\-0.1.0-beta.1","description":"Release mock"},{"revision":4,"updated":".*","status":"deployed","chart":"foo\-0.1.0-beta.1","description":"Release mock"}]\n`, + golden: "output/history.yaml", + }, { + name: "get history with json output format", + cmd: "history angry-bird --output json", + rels: []*rpb.Release{ + mk("angry-bird", 4, rpb.StatusDeployed), + mk("angry-bird", 3, rpb.StatusSuperseded), }, - } + golden: "output/history.json", + }} testReleaseCmd(t, tests) } diff --git a/cmd/helm/install_test.go b/cmd/helm/install_test.go index a384c299a..397805345 100644 --- a/cmd/helm/install_test.go +++ b/cmd/helm/install_test.go @@ -20,87 +20,76 @@ import ( "reflect" "regexp" "testing" - - "k8s.io/helm/pkg/helm" ) func TestInstall(t *testing.T) { tests := []releaseCase{ // Install, base case { - name: "basic install", - cmd: "install testdata/testcharts/alpine --name aeneas", - matches: "aeneas", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "aeneas"}), + name: "basic install", + cmd: "install testdata/testcharts/alpine --name aeneas", + golden: "output/install.txt", }, // Install, no hooks { - name: "install without hooks", - cmd: "install testdata/testcharts/alpine --name aeneas --no-hooks", - matches: "aeneas", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "aeneas"}), + name: "install without hooks", + cmd: "install testdata/testcharts/alpine --name aeneas --no-hooks", + golden: "output/install-no-hooks.txt", }, // Install, values from cli { - name: "install with values", - cmd: "install testdata/testcharts/alpine --name virgil --set foo=bar", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "virgil"}), - matches: "virgil", + name: "install with values", + cmd: "install testdata/testcharts/alpine --name virgil --set foo=bar", + golden: "output/install-with-values.txt", }, // Install, values from cli via multiple --set { - name: "install with multiple values", - cmd: "install testdata/testcharts/alpine --name virgil --set foo=bar --set bar=foo", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "virgil"}), - matches: "virgil", + name: "install with multiple values", + cmd: "install testdata/testcharts/alpine --name virgil --set foo=bar --set bar=foo", + golden: "output/install-with-multiple-values.txt", }, // Install, values from yaml { - name: "install with values", - cmd: "install testdata/testcharts/alpine --name virgil -f testdata/testcharts/alpine/extra_values.yaml", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "virgil"}), - matches: "virgil", + name: "install with values file", + cmd: "install testdata/testcharts/alpine --name virgil -f testdata/testcharts/alpine/extra_values.yaml", + golden: "output/install-with-values-file.txt", }, // Install, values from multiple yaml { - name: "install with values", - cmd: "install testdata/testcharts/alpine --name virgil -f testdata/testcharts/alpine/extra_values.yaml -f testdata/testcharts/alpine/more_values.yaml", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "virgil"}), - matches: "virgil", + name: "install with values", + cmd: "install testdata/testcharts/alpine --name virgil -f testdata/testcharts/alpine/extra_values.yaml -f testdata/testcharts/alpine/more_values.yaml", + golden: "output/install-with-multiple-values-files.txt", }, // Install, no charts { name: "install with no chart specified", cmd: "install", + golden: "output/install-no-args.txt", wantError: true, }, // Install, re-use name { - name: "install and replace release", - cmd: "install testdata/testcharts/alpine --name aeneas --replace", - matches: "aeneas", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "aeneas"}), + name: "install and replace release", + cmd: "install testdata/testcharts/alpine --name aeneas --replace", + golden: "output/install-and-replace.txt", }, // Install, with timeout { - name: "install with a timeout", - cmd: "install testdata/testcharts/alpine --name foobar --timeout 120", - matches: "foobar", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "foobar"}), + name: "install with a timeout", + cmd: "install testdata/testcharts/alpine --name foobar --timeout 120", + golden: "output/install-with-timeout.txt", }, // Install, with wait { - name: "install with a wait", - cmd: "install testdata/testcharts/alpine --name apollo --wait", - matches: "apollo", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "apollo"}), + name: "install with a wait", + cmd: "install testdata/testcharts/alpine --name apollo --wait", + golden: "output/install-with-wait.txt", }, // Install, using the name-template { - name: "install with name-template", - cmd: "install testdata/testcharts/alpine --name-template '{{upper \"foobar\"}}'", - matches: "FOOBAR", - resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "FOOBAR"}), + name: "install with name-template", + cmd: "install testdata/testcharts/alpine --name-template '{{upper \"foobar\"}}'", + golden: "output/install-name-template.txt", }, // Install, perform chart verification along the way. { diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 054df6271..b2df59a7a 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -115,14 +115,14 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { } func (l *listCmd) run() error { - sortBy := hapi.ListSortName + sortBy := hapi.SortByName if l.byDate { - sortBy = hapi.ListSortLastReleased + sortBy = hapi.SortByLastReleased } - sortOrder := hapi.ListSortAsc + sortOrder := hapi.SortAsc if l.sortDesc { - sortOrder = hapi.ListSortDesc + sortOrder = hapi.SortDesc } stats := l.statusCodes() diff --git a/cmd/helm/list_test.go b/cmd/helm/list_test.go index 9358fdf79..efffaf070 100644 --- a/cmd/helm/list_test.go +++ b/cmd/helm/list_test.go @@ -24,103 +24,92 @@ import ( ) func TestListCmd(t *testing.T) { - tests := []releaseCase{ - { - name: "with a release", - cmd: "list", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}), - }, - matches: "thomas-guide", + tests := []releaseCase{{ + name: "with a release", + cmd: "list", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}), }, - { - name: "list", - cmd: "list", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas"}), - }, - matches: `NAME\s+REVISION\s+UPDATED\s+STATUS\s+CHART\s+NAMESPACE\natlas\s+1\s+(.*)\s+deployed\s+foo-0.1.0-beta.1\s+default`, + golden: "output/list-with-release.txt", + }, { + name: "list", + cmd: "list", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas"}), }, - { - name: "list, one deployed, one failed", - cmd: "list -q", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusFailed}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), - }, - matches: "thomas-guide\natlas-guide", + golden: "output/list.txt", + }, { + name: "list, one deployed, one failed", + cmd: "list -q", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusFailed}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), }, - { - name: "with a release, multiple flags", - cmd: "list --deleted --deployed --failed -q", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusDeleted}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), - }, - // Note: We're really only testing that the flags parsed correctly. Which results are returned - // depends on the backend. And until pkg/helm is done, we can't mock this. - matches: "thomas-guide\natlas-guide", + golden: "output/list-with-failed.txt", + }, { + name: "with a release, multiple flags", + cmd: "list --deleted --deployed --failed -q", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusDeleted}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), }, - { - name: "with a release, multiple flags", - cmd: "list --all -q", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusDeleted}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), - }, - // See note on previous test. - matches: "thomas-guide\natlas-guide", + // Note: We're really only testing that the flags parsed correctly. Which results are returned + // depends on the backend. And until pkg/helm is done, we can't mock this. + golden: "output/list-with-mulitple-flags.txt", + }, { + name: "with a release, multiple flags", + cmd: "list --all -q", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusDeleted}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), }, - { - name: "with a release, multiple flags, deleting", - cmd: "list --all -q", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusDeleting}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), - }, - // See note on previous test. - matches: "thomas-guide\natlas-guide", + // See note on previous test. + golden: "output/list-with-mulitple-flags2.txt", + }, { + name: "with a release, multiple flags, deleting", + cmd: "list --all -q", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusDeleting}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), }, - { - name: "namespace defined, multiple flags", - cmd: "list --all -q --namespace test123", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Namespace: "test123"}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Namespace: "test321"}), - }, - // See note on previous test. - matches: "thomas-guide", + // See note on previous test. + golden: "output/list-with-mulitple-flags-deleting.txt", + }, { + name: "namespace defined, multiple flags", + cmd: "list --all -q --namespace test123", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Namespace: "test123"}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Namespace: "test321"}), }, - { - name: "with a pending release, multiple flags", - cmd: "list --all -q", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusPendingInstall}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), - }, - matches: "thomas-guide\natlas-guide", + // See note on previous test. + golden: "output/list-with-mulitple-flags-namespaced.txt", + }, { + name: "with a pending release, multiple flags", + cmd: "list --all -q", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusPendingInstall}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), }, - { - name: "with a pending release, pending flag", - cmd: "list --pending -q", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusPendingInstall}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "wild-idea", Status: release.StatusPendingUpgrade}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "crazy-maps", Status: release.StatusPendingRollback}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), - }, - matches: "thomas-guide\nwild-idea\ncrazy-maps", + golden: "output/list-with-mulitple-flags-pending.txt", + }, { + name: "with a pending release, pending flag", + cmd: "list --pending -q", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusPendingInstall}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "wild-idea", Status: release.StatusPendingUpgrade}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "crazy-maps", Status: release.StatusPendingRollback}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "atlas-guide", Status: release.StatusDeployed}), }, - { - name: "with old releases", - cmd: "list", - rels: []*release.Release{ - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}), - helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusFailed}), - }, - matches: "thomas-guide", + golden: "output/list-with-pending.txt", + }, { + name: "with old releases", + cmd: "list", + rels: []*release.Release{ + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide"}), + helm.ReleaseMock(&helm.MockReleaseOptions{Name: "thomas-guide", Status: release.StatusFailed}), }, - } + golden: "output/list-with-old-releases.txt", + }} testReleaseCmd(t, tests) } diff --git a/cmd/helm/package_test.go b/cmd/helm/package_test.go index 932870836..ead7c7fb1 100644 --- a/cmd/helm/package_test.go +++ b/cmd/helm/package_test.go @@ -151,7 +151,7 @@ func TestPackage(t *testing.T) { t.Fatal(err) } - ensureTestHome(helmpath.Home(tmp), t) + ensureTestHome(t, helmpath.Home(tmp)) cleanup := resetEnv() defer func() { os.Chdir(origDir) diff --git a/cmd/helm/release_testing_test.go b/cmd/helm/release_testing_test.go index 36b9365a8..6213cda33 100644 --- a/cmd/helm/release_testing_test.go +++ b/cmd/helm/release_testing_test.go @@ -23,49 +23,44 @@ import ( ) func TestReleaseTesting(t *testing.T) { - tests := []releaseCase{ - { - name: "basic test", - cmd: "test example-release", - responses: map[string]release.TestRunStatus{"PASSED: green lights everywhere": release.TestRunSuccess}, - wantError: false, - }, - { - name: "test failure", - cmd: "test example-fail", - responses: map[string]release.TestRunStatus{"FAILURE: red lights everywhere": release.TestRunFailure}, - wantError: true, - }, - { - name: "test unknown", - cmd: "test example-unknown", - responses: map[string]release.TestRunStatus{"UNKNOWN: yellow lights everywhere": release.TestRunUnknown}, - wantError: false, - }, - { - name: "test error", - cmd: "test example-error", - responses: map[string]release.TestRunStatus{"ERROR: yellow lights everywhere": release.TestRunFailure}, - wantError: true, - }, - { - name: "test running", - cmd: "test example-running", - responses: map[string]release.TestRunStatus{"RUNNING: things are happpeningggg": release.TestRunRunning}, - wantError: false, - }, - { - name: "multiple tests example", - cmd: "test example-suite", - responses: map[string]release.TestRunStatus{ - "RUNNING: things are happpeningggg": release.TestRunRunning, - "PASSED: party time": release.TestRunSuccess, - "RUNNING: things are happening again": release.TestRunRunning, - "FAILURE: good thing u checked :)": release.TestRunFailure, - "RUNNING: things are happpeningggg yet again": release.TestRunRunning, - "PASSED: feel free to party again": release.TestRunSuccess}, - wantError: true, - }, - } + tests := []releaseCase{{ + name: "basic test", + cmd: "test example-release", + testRunStatus: map[string]release.TestRunStatus{"PASSED: green lights everywhere": release.TestRunSuccess}, + golden: "output/test.txt", + }, { + name: "test failure", + cmd: "test example-fail", + testRunStatus: map[string]release.TestRunStatus{"FAILURE: red lights everywhere": release.TestRunFailure}, + wantError: true, + golden: "output/test-failure.txt", + }, { + name: "test unknown", + cmd: "test example-unknown", + testRunStatus: map[string]release.TestRunStatus{"UNKNOWN: yellow lights everywhere": release.TestRunUnknown}, + golden: "output/test-unknown.txt", + }, { + name: "test error", + cmd: "test example-error", + testRunStatus: map[string]release.TestRunStatus{"ERROR: yellow lights everywhere": release.TestRunFailure}, + wantError: true, + golden: "output/test-error.txt", + }, { + name: "test running", + cmd: "test example-running", + testRunStatus: map[string]release.TestRunStatus{"RUNNING: things are happpeningggg": release.TestRunRunning}, + golden: "output/test-running.txt", + }, { + name: "multiple tests example", + cmd: "test example-suite", + testRunStatus: map[string]release.TestRunStatus{ + "RUNNING: things are happpeningggg": release.TestRunRunning, + "PASSED: party time": release.TestRunSuccess, + "RUNNING: things are happening again": release.TestRunRunning, + "FAILURE: good thing u checked :)": release.TestRunFailure, + "RUNNING: things are happpeningggg yet again": release.TestRunRunning, + "PASSED: feel free to party again": release.TestRunSuccess}, + wantError: true, + }} testReleaseCmd(t, tests) } diff --git a/cmd/helm/repo_add_test.go b/cmd/helm/repo_add_test.go index f72745cb7..4f4f041da 100644 --- a/cmd/helm/repo_add_test.go +++ b/cmd/helm/repo_add_test.go @@ -25,8 +25,6 @@ import ( "k8s.io/helm/pkg/repo/repotest" ) -var testName = "test-name" - func TestRepoAddCmd(t *testing.T) { srv, thome, err := repotest.NewTempServer("testdata/testserver/*.*") if err != nil { @@ -39,16 +37,16 @@ func TestRepoAddCmd(t *testing.T) { os.RemoveAll(thome.String()) cleanup() }() - if err := ensureTestHome(thome, t); err != nil { + if err := ensureTestHome(t, thome); err != nil { t.Fatal(err) } settings.Home = thome tests := []releaseCase{{ - name: "add a repository", - cmd: fmt.Sprintf("repo add %s %s --home %s", testName, srv.URL(), thome), - matches: "\"" + testName + "\" has been added to your repositories", + name: "add a repository", + cmd: fmt.Sprintf("repo add test-name %s --home %s", srv.URL(), thome), + golden: "output/repo-add.txt", }} testReleaseCmd(t, tests) @@ -67,13 +65,15 @@ func TestRepoAdd(t *testing.T) { os.RemoveAll(thome.String()) cleanup() }() - if err := ensureTestHome(hh, t); err != nil { + if err := ensureTestHome(t, hh); err != nil { t.Fatal(err) } settings.Home = thome - if err := addRepository(testName, ts.URL(), "", "", hh, "", "", "", true); err != nil { + const testRepoName = "test-name" + + if err := addRepository(testRepoName, ts.URL(), "", "", hh, "", "", "", true); err != nil { t.Error(err) } @@ -82,15 +82,15 @@ func TestRepoAdd(t *testing.T) { t.Error(err) } - if !f.Has(testName) { - t.Errorf("%s was not successfully inserted into %s", testName, hh.RepositoryFile()) + if !f.Has(testRepoName) { + t.Errorf("%s was not successfully inserted into %s", testRepoName, hh.RepositoryFile()) } - if err := addRepository(testName, ts.URL(), "", "", hh, "", "", "", false); err != nil { + if err := addRepository(testRepoName, ts.URL(), "", "", hh, "", "", "", false); err != nil { t.Errorf("Repository was not updated: %s", err) } - if err := addRepository(testName, ts.URL(), "", "", hh, "", "", "", false); err != nil { + if err := addRepository(testRepoName, ts.URL(), "", "", hh, "", "", "", false); err != nil { t.Errorf("Duplicate repository name was added") } } diff --git a/cmd/helm/repo_remove_test.go b/cmd/helm/repo_remove_test.go index 174a44495..7b7ad5a5d 100644 --- a/cmd/helm/repo_remove_test.go +++ b/cmd/helm/repo_remove_test.go @@ -40,34 +40,35 @@ func TestRepoRemove(t *testing.T) { os.RemoveAll(thome.String()) cleanup() }() - if err := ensureTestHome(hh, t); err != nil { + if err := ensureTestHome(t, hh); err != nil { t.Fatal(err) } settings.Home = thome - b := bytes.NewBuffer(nil) + const testRepoName = "test-name" - if err := removeRepoLine(b, testName, hh); err == nil { - t.Errorf("Expected error removing %s, but did not get one.", testName) + b := bytes.NewBuffer(nil) + if err := removeRepoLine(b, testRepoName, hh); err == nil { + t.Errorf("Expected error removing %s, but did not get one.", testRepoName) } - if err := addRepository(testName, ts.URL(), "", "", hh, "", "", "", true); err != nil { + if err := addRepository(testRepoName, ts.URL(), "", "", hh, "", "", "", true); err != nil { t.Error(err) } - mf, _ := os.Create(hh.CacheIndex(testName)) + mf, _ := os.Create(hh.CacheIndex(testRepoName)) mf.Close() b.Reset() - if err := removeRepoLine(b, testName, hh); err != nil { - t.Errorf("Error removing %s from repositories", testName) + if err := removeRepoLine(b, testRepoName, hh); err != nil { + t.Errorf("Error removing %s from repositories", testRepoName) } if !strings.Contains(b.String(), "has been removed") { t.Errorf("Unexpected output: %s", b.String()) } - if _, err := os.Stat(hh.CacheIndex(testName)); err == nil { - t.Errorf("Error cache file was not removed for repository %s", testName) + if _, err := os.Stat(hh.CacheIndex(testRepoName)); err == nil { + t.Errorf("Error cache file was not removed for repository %s", testRepoName) } f, err := repo.LoadRepositoriesFile(hh.RepositoryFile()) @@ -75,7 +76,7 @@ func TestRepoRemove(t *testing.T) { t.Error(err) } - if f.Has(testName) { - t.Errorf("%s was not successfully removed from repositories list", testName) + if f.Has(testRepoName) { + t.Errorf("%s was not successfully removed from repositories list", testRepoName) } } diff --git a/cmd/helm/repo_update_test.go b/cmd/helm/repo_update_test.go index be96f79da..5dac59130 100644 --- a/cmd/helm/repo_update_test.go +++ b/cmd/helm/repo_update_test.go @@ -78,7 +78,7 @@ func TestUpdateCharts(t *testing.T) { os.RemoveAll(thome.String()) cleanup() }() - if err := ensureTestHome(hh, t); err != nil { + if err := ensureTestHome(t, hh); err != nil { t.Fatal(err) } diff --git a/cmd/helm/rollback_test.go b/cmd/helm/rollback_test.go index 3b0839312..fd78c4d0d 100644 --- a/cmd/helm/rollback_test.go +++ b/cmd/helm/rollback_test.go @@ -21,28 +21,23 @@ import ( ) func TestRollbackCmd(t *testing.T) { - - tests := []releaseCase{ - { - name: "rollback a release", - cmd: "rollback funny-honey 1", - matches: "Rollback was a success! Happy Helming!", - }, - { - name: "rollback a release with timeout", - cmd: "rollback funny-honey 1 --timeout 120", - matches: "Rollback was a success! Happy Helming!", - }, - { - name: "rollback a release with wait", - cmd: "rollback funny-honey 1 --wait", - matches: "Rollback was a success! Happy Helming!", - }, - { - name: "rollback a release without revision", - cmd: "rollback funny-honey", - wantError: true, - }, - } + tests := []releaseCase{{ + name: "rollback a release", + cmd: "rollback funny-honey 1", + golden: "output/rollback.txt", + }, { + name: "rollback a release with timeout", + cmd: "rollback funny-honey 1 --timeout 120", + golden: "output/rollback-timeout.txt", + }, { + name: "rollback a release with wait", + cmd: "rollback funny-honey 1 --wait", + golden: "output/rollback-wait.txt", + }, { + name: "rollback a release without revision", + cmd: "rollback funny-honey", + golden: "output/rollback-no-args.txt", + wantError: true, + }} testReleaseCmd(t, tests) } diff --git a/cmd/helm/search_test.go b/cmd/helm/search_test.go index 6541046b9..27d8c6c3e 100644 --- a/cmd/helm/search_test.go +++ b/cmd/helm/search_test.go @@ -21,58 +21,47 @@ import ( ) func TestSearchCmd(t *testing.T) { - tests := []releaseCase{ - { - name: "search for 'maria', expect one match", - cmd: "search maria", - matches: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/mariadb\t0.3.0 \t \tChart for MariaDB", - }, - { - name: "search for 'alpine', expect two matches", - cmd: "search alpine", - matches: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod", - }, - { - name: "search for 'alpine' with versions, expect three matches", - cmd: "search alpine --versions", - matches: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod\ntesting/alpine\t0.1.0 \t1.2.3 \tDeploy a basic Alpine Linux pod", - }, - { - name: "search for 'alpine' with version constraint, expect one match with version 0.1.0", - cmd: "search alpine --version '>= 0.1, < 0.2'", - matches: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.1.0 \t1.2.3 \tDeploy a basic Alpine Linux pod", - }, - { - name: "search for 'alpine' with version constraint, expect one match with version 0.1.0", - cmd: "search alpine --versions --version '>= 0.1, < 0.2'", - matches: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.1.0 \t1.2.3 \tDeploy a basic Alpine Linux pod", - }, - { - name: "search for 'alpine' with version constraint, expect one match with version 0.2.0", - cmd: "search alpine --version '>= 0.1'", - matches: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod", - }, - { - name: "search for 'alpine' with version constraint and --versions, expect two matches", - cmd: "search alpine --versions --version '>= 0.1'", - matches: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod\ntesting/alpine\t0.1.0 \t1.2.3 \tDeploy a basic Alpine Linux pod", - }, - { - name: "search for 'syzygy', expect no matches", - cmd: "search syzygy", - matches: "No results found", - }, - { - name: "search for 'alp[a-z]+', expect two matches", - cmd: "search alp[a-z]+ --regexp", - matches: "NAME \tCHART VERSION\tAPP VERSION\tDESCRIPTION \ntesting/alpine\t0.2.0 \t2.3.4 \tDeploy a basic Alpine Linux pod", - }, - { - name: "search for 'alp[', expect failure to compile regexp", - cmd: "search alp[ --regexp", - wantError: true, - }, - } + tests := []releaseCase{{ + name: "search for 'maria', expect one match", + cmd: "search maria", + golden: "output/search-single.txt", + }, { + name: "search for 'alpine', expect two matches", + cmd: "search alpine", + golden: "output/search-multiple.txt", + }, { + name: "search for 'alpine' with versions, expect three matches", + cmd: "search alpine --versions", + golden: "output/search-multiple-versions.txt", + }, { + name: "search for 'alpine' with version constraint, expect one match with version 0.1.0", + cmd: "search alpine --version '>= 0.1, < 0.2'", + golden: "output/search-constraint.txt", + }, { + name: "search for 'alpine' with version constraint, expect one match with version 0.1.0", + cmd: "search alpine --versions --version '>= 0.1, < 0.2'", + golden: "output/search-versions-constraint.txt", + }, { + name: "search for 'alpine' with version constraint, expect one match with version 0.2.0", + cmd: "search alpine --version '>= 0.1'", + golden: "output/search-constraint-single.txt", + }, { + name: "search for 'alpine' with version constraint and --versions, expect two matches", + cmd: "search alpine --versions --version '>= 0.1'", + golden: "output/search-multiple-versions-constraints.txt", + }, { + name: "search for 'syzygy', expect no matches", + cmd: "search syzygy", + golden: "output/search-not-found.txt", + }, { + name: "search for 'alp[a-z]+', expect two matches", + cmd: "search alp[a-z]+ --regexp", + golden: "output/search-regex.txt", + }, { + name: "search for 'alp[', expect failure to compile regexp", + cmd: "search alp[ --regexp", + wantError: true, + }} cleanup := resetEnv() defer cleanup() diff --git a/cmd/helm/status_test.go b/cmd/helm/status_test.go index 83eb3055e..c94d278a3 100644 --- a/cmd/helm/status_test.go +++ b/cmd/helm/status_test.go @@ -17,7 +17,6 @@ limitations under the License. package main import ( - "fmt" "testing" "time" @@ -25,107 +24,70 @@ import ( ) func TestStatusCmd(t *testing.T) { - tests := []releaseCase{ - { - name: "get status of a deployed release", - cmd: "status flummoxed-chickadee", - matches: outputWithStatus("deployed"), - rels: []*release.Release{ - releaseMockWithStatus(&release.Info{ - Status: release.StatusDeployed, - }), - }, - }, - { - name: "get status of a deployed release with notes", - cmd: "status flummoxed-chickadee", - matches: outputWithStatus("deployed\n\nNOTES:\nrelease notes\n"), - rels: []*release.Release{ - releaseMockWithStatus(&release.Info{ - Status: release.StatusDeployed, - Notes: "release notes", - }), - }, - }, - { - name: "get status of a deployed release with notes in json", - cmd: "status flummoxed-chickadee -o json", - matches: `{"name":"flummoxed-chickadee","info":{"first_deployed":(.*),"last_deployed":(.*),"deleted":(.*),"status":"deployed","notes":"release notes"}}`, - rels: []*release.Release{ - releaseMockWithStatus(&release.Info{ - Status: release.StatusDeployed, - Notes: "release notes", - }), - }, - }, - { - name: "get status of a deployed release with resources", - cmd: "status flummoxed-chickadee", - matches: outputWithStatus("deployed\n\nRESOURCES:\nresource A\nresource B\n\n"), - rels: []*release.Release{ - releaseMockWithStatus(&release.Info{ - Status: release.StatusDeployed, - Resources: "resource A\nresource B\n", - }), - }, - }, - { - name: "get status of a deployed release with resources in YAML", - cmd: "status flummoxed-chickadee -o yaml", - matches: `info:\n deleted: .*\n first_deployed: .*\n last_deployed: .*\n resources: |\n resource A\n resource B\n status: deployed\nname: flummoxed-chickadee\n`, - rels: []*release.Release{ - releaseMockWithStatus(&release.Info{ - Status: release.StatusDeployed, - Resources: "resource A\nresource B\n", - }), - }, - }, - { - name: "get status of a deployed release with test suite", - cmd: "status flummoxed-chickadee", - matches: outputWithStatus( - "deployed\n\nTEST SUITE:\nLast Started: (.*)\nLast Completed: (.*)\n\n" + - "TEST \tSTATUS (.*)\tINFO (.*)\tSTARTED (.*)\tCOMPLETED (.*)\n" + - "test run 1\tsuccess (.*)\textra info\t(.*)\t(.*)\n" + - "test run 2\tfailure (.*)\t (.*)\t(.*)\t(.*)\n"), - rels: []*release.Release{ - releaseMockWithStatus(&release.Info{ - Status: release.StatusDeployed, - LastTestSuiteRun: &release.TestSuite{ - StartedAt: time.Now(), - CompletedAt: time.Now(), - Results: []*release.TestRun{ - { - Name: "test run 1", - Status: release.TestRunSuccess, - Info: "extra info", - StartedAt: time.Now(), - CompletedAt: time.Now(), - }, - { - Name: "test run 2", - Status: release.TestRunFailure, - StartedAt: time.Now(), - CompletedAt: time.Now(), - }, - }, - }, - }), - }, - }, + releasesMockWithStatus := func(info *release.Info) []*release.Release { + info.LastDeployed = time.Unix(1452902400, 0) + return []*release.Release{{ + Name: "flummoxed-chickadee", + Info: info, + }} } - testReleaseCmd(t, tests) -} - -func outputWithStatus(status string) string { - return fmt.Sprintf(`LAST DEPLOYED:(.*)\nNAMESPACE: \nSTATUS: %s`, status) -} -func releaseMockWithStatus(info *release.Info) *release.Release { - info.FirstDeployed = time.Now() - info.LastDeployed = time.Now() - return &release.Release{ - Name: "flummoxed-chickadee", - Info: info, - } + tests := []releaseCase{{ + name: "get status of a deployed release", + cmd: "status flummoxed-chickadee", + golden: "output/status.txt", + rels: releasesMockWithStatus(&release.Info{ + Status: release.StatusDeployed, + }), + }, { + name: "get status of a deployed release with notes", + cmd: "status flummoxed-chickadee", + golden: "output/status-with-notes.txt", + rels: releasesMockWithStatus(&release.Info{ + Status: release.StatusDeployed, + Notes: "release notes", + }), + }, { + name: "get status of a deployed release with notes in json", + cmd: "status flummoxed-chickadee -o json", + golden: "output/status.json", + rels: releasesMockWithStatus(&release.Info{ + Status: release.StatusDeployed, + Notes: "release notes", + }), + }, { + name: "get status of a deployed release with resources", + cmd: "status flummoxed-chickadee", + golden: "output/status-with-resource.txt", + rels: releasesMockWithStatus(&release.Info{ + Status: release.StatusDeployed, + Resources: "resource A\nresource B\n", + }), + }, { + name: "get status of a deployed release with resources in YAML", + cmd: "status flummoxed-chickadee -o yaml", + golden: "output/status.yaml", + rels: releasesMockWithStatus(&release.Info{ + Status: release.StatusDeployed, + Resources: "resource A\nresource B\n", + }), + }, { + name: "get status of a deployed release with test suite", + cmd: "status flummoxed-chickadee", + golden: "output/status-with-test-suite.txt", + rels: releasesMockWithStatus(&release.Info{ + Status: release.StatusDeployed, + LastTestSuiteRun: &release.TestSuite{ + Results: []*release.TestRun{{ + Name: "test run 1", + Status: release.TestRunSuccess, + Info: "extra info", + }, { + Name: "test run 2", + Status: release.TestRunFailure, + }}, + }, + }), + }} + testReleaseCmd(t, tests) } diff --git a/cmd/helm/testdata/output/delete-no-args.txt b/cmd/helm/testdata/output/delete-no-args.txt new file mode 100644 index 000000000..8fa7e2d3f --- /dev/null +++ b/cmd/helm/testdata/output/delete-no-args.txt @@ -0,0 +1 @@ +Error: command 'delete' requires a release name diff --git a/cmd/helm/testdata/output/delete-no-hooks.txt b/cmd/helm/testdata/output/delete-no-hooks.txt new file mode 100644 index 000000000..1292e5eb7 --- /dev/null +++ b/cmd/helm/testdata/output/delete-no-hooks.txt @@ -0,0 +1 @@ +release "aeneas" deleted diff --git a/cmd/helm/testdata/output/delete-purge.txt b/cmd/helm/testdata/output/delete-purge.txt new file mode 100644 index 000000000..1292e5eb7 --- /dev/null +++ b/cmd/helm/testdata/output/delete-purge.txt @@ -0,0 +1 @@ +release "aeneas" deleted diff --git a/cmd/helm/testdata/output/delete-timeout.txt b/cmd/helm/testdata/output/delete-timeout.txt new file mode 100644 index 000000000..1292e5eb7 --- /dev/null +++ b/cmd/helm/testdata/output/delete-timeout.txt @@ -0,0 +1 @@ +release "aeneas" deleted diff --git a/cmd/helm/testdata/output/delete.txt b/cmd/helm/testdata/output/delete.txt new file mode 100644 index 000000000..1292e5eb7 --- /dev/null +++ b/cmd/helm/testdata/output/delete.txt @@ -0,0 +1 @@ +release "aeneas" deleted diff --git a/cmd/helm/testdata/output/dependency-list-archive.txt b/cmd/helm/testdata/output/dependency-list-archive.txt new file mode 100644 index 000000000..098bc0635 --- /dev/null +++ b/cmd/helm/testdata/output/dependency-list-archive.txt @@ -0,0 +1,4 @@ +NAME VERSION REPOSITORY STATUS +reqsubchart 0.1.0 https://example.com/charts missing +reqsubchart2 0.2.0 https://example.com/charts missing + diff --git a/cmd/helm/testdata/output/dependency-list-no-chart.txt b/cmd/helm/testdata/output/dependency-list-no-chart.txt new file mode 100644 index 000000000..8fab8f8eb --- /dev/null +++ b/cmd/helm/testdata/output/dependency-list-no-chart.txt @@ -0,0 +1 @@ +Error: stat /no/such/chart: no such file or directory diff --git a/cmd/helm/testdata/output/dependency-list-no-requirements.txt b/cmd/helm/testdata/output/dependency-list-no-requirements.txt new file mode 100644 index 000000000..7e698e627 --- /dev/null +++ b/cmd/helm/testdata/output/dependency-list-no-requirements.txt @@ -0,0 +1 @@ +WARNING: no requirements at testdata/testcharts/alpine/charts diff --git a/cmd/helm/testdata/output/dependency-list.txt b/cmd/helm/testdata/output/dependency-list.txt new file mode 100644 index 000000000..b57c21a21 --- /dev/null +++ b/cmd/helm/testdata/output/dependency-list.txt @@ -0,0 +1,5 @@ +NAME VERSION REPOSITORY STATUS +reqsubchart 0.1.0 https://example.com/charts unpacked +reqsubchart2 0.2.0 https://example.com/charts unpacked +reqsubchart3 >=0.1.0 https://example.com/charts ok + diff --git a/cmd/helm/testdata/output/get-hooks-no-args.txt b/cmd/helm/testdata/output/get-hooks-no-args.txt new file mode 100644 index 000000000..3d0b2a17a --- /dev/null +++ b/cmd/helm/testdata/output/get-hooks-no-args.txt @@ -0,0 +1 @@ +Error: release name is required diff --git a/cmd/helm/testdata/output/get-hooks.txt b/cmd/helm/testdata/output/get-hooks.txt new file mode 100644 index 000000000..e8ba823d6 --- /dev/null +++ b/cmd/helm/testdata/output/get-hooks.txt @@ -0,0 +1,7 @@ +--- +# pre-install-hook +apiVersion: v1 +kind: Job +metadata: + annotations: + "helm.sh/hook": pre-install diff --git a/cmd/helm/testdata/output/get-manifest-no-args.txt b/cmd/helm/testdata/output/get-manifest-no-args.txt new file mode 100644 index 000000000..3d0b2a17a --- /dev/null +++ b/cmd/helm/testdata/output/get-manifest-no-args.txt @@ -0,0 +1 @@ +Error: release name is required diff --git a/cmd/helm/testdata/output/get-manifest.txt b/cmd/helm/testdata/output/get-manifest.txt new file mode 100644 index 000000000..88937e089 --- /dev/null +++ b/cmd/helm/testdata/output/get-manifest.txt @@ -0,0 +1,5 @@ +apiVersion: v1 +kind: Secret +metadata: + name: fixture + diff --git a/cmd/helm/testdata/output/get-no-args.txt b/cmd/helm/testdata/output/get-no-args.txt new file mode 100644 index 000000000..3d0b2a17a --- /dev/null +++ b/cmd/helm/testdata/output/get-no-args.txt @@ -0,0 +1 @@ +Error: release name is required diff --git a/cmd/helm/testdata/output/get-release.txt b/cmd/helm/testdata/output/get-release.txt new file mode 100644 index 000000000..844712011 --- /dev/null +++ b/cmd/helm/testdata/output/get-release.txt @@ -0,0 +1,23 @@ +REVISION: 1 +RELEASED: Fri Sep 2 22:04:05 1977 +CHART: foo-0.1.0-beta.1 +USER-SUPPLIED VALUES: +name: "value" +COMPUTED VALUES: +name: value + +HOOKS: +--- +# pre-install-hook +apiVersion: v1 +kind: Job +metadata: + annotations: + "helm.sh/hook": pre-install + +MANIFEST: +apiVersion: v1 +kind: Secret +metadata: + name: fixture + diff --git a/cmd/helm/testdata/output/get-values-args.txt b/cmd/helm/testdata/output/get-values-args.txt new file mode 100644 index 000000000..3d0b2a17a --- /dev/null +++ b/cmd/helm/testdata/output/get-values-args.txt @@ -0,0 +1 @@ +Error: release name is required diff --git a/cmd/helm/testdata/output/get-values.txt b/cmd/helm/testdata/output/get-values.txt new file mode 100644 index 000000000..e6ad584a9 --- /dev/null +++ b/cmd/helm/testdata/output/get-values.txt @@ -0,0 +1 @@ +name: "value" diff --git a/cmd/helm/testdata/output/history-limit.txt b/cmd/helm/testdata/output/history-limit.txt new file mode 100644 index 000000000..48c900c86 --- /dev/null +++ b/cmd/helm/testdata/output/history-limit.txt @@ -0,0 +1,3 @@ +REVISION UPDATED STATUS CHART DESCRIPTION +3 1977-09-02 22:04:05 +0000 UTC superseded foo-0.1.0-beta.1 Release mock +4 1977-09-02 22:04:05 +0000 UTC deployed foo-0.1.0-beta.1 Release mock diff --git a/cmd/helm/testdata/output/history.json b/cmd/helm/testdata/output/history.json new file mode 100644 index 000000000..e16b5670e --- /dev/null +++ b/cmd/helm/testdata/output/history.json @@ -0,0 +1 @@ +[{"revision":3,"updated":"1977-09-02 22:04:05 +0000 UTC","status":"superseded","chart":"foo-0.1.0-beta.1","description":"Release mock"},{"revision":4,"updated":"1977-09-02 22:04:05 +0000 UTC","status":"deployed","chart":"foo-0.1.0-beta.1","description":"Release mock"}] diff --git a/cmd/helm/testdata/output/history.txt b/cmd/helm/testdata/output/history.txt new file mode 100644 index 000000000..e2379f721 --- /dev/null +++ b/cmd/helm/testdata/output/history.txt @@ -0,0 +1,5 @@ +REVISION UPDATED STATUS CHART DESCRIPTION +1 1977-09-02 22:04:05 +0000 UTC superseded foo-0.1.0-beta.1 Release mock +2 1977-09-02 22:04:05 +0000 UTC superseded foo-0.1.0-beta.1 Release mock +3 1977-09-02 22:04:05 +0000 UTC superseded foo-0.1.0-beta.1 Release mock +4 1977-09-02 22:04:05 +0000 UTC deployed foo-0.1.0-beta.1 Release mock diff --git a/cmd/helm/testdata/output/history.yaml b/cmd/helm/testdata/output/history.yaml new file mode 100644 index 000000000..042b87118 --- /dev/null +++ b/cmd/helm/testdata/output/history.yaml @@ -0,0 +1,11 @@ +- chart: foo-0.1.0-beta.1 + description: Release mock + revision: 3 + status: superseded + updated: 1977-09-02 22:04:05 +0000 UTC +- chart: foo-0.1.0-beta.1 + description: Release mock + revision: 4 + status: deployed + updated: 1977-09-02 22:04:05 +0000 UTC + diff --git a/cmd/helm/testdata/output/install-and-replace.txt b/cmd/helm/testdata/output/install-and-replace.txt new file mode 100644 index 000000000..4df13b70e --- /dev/null +++ b/cmd/helm/testdata/output/install-and-replace.txt @@ -0,0 +1,5 @@ +NAME: aeneas +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/install-name-template.txt b/cmd/helm/testdata/output/install-name-template.txt new file mode 100644 index 000000000..4389775ab --- /dev/null +++ b/cmd/helm/testdata/output/install-name-template.txt @@ -0,0 +1,5 @@ +NAME: FOOBAR +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/install-no-args.txt b/cmd/helm/testdata/output/install-no-args.txt new file mode 100644 index 000000000..6e40280f9 --- /dev/null +++ b/cmd/helm/testdata/output/install-no-args.txt @@ -0,0 +1 @@ +Error: This command needs 1 argument: chart name diff --git a/cmd/helm/testdata/output/install-no-hooks.txt b/cmd/helm/testdata/output/install-no-hooks.txt new file mode 100644 index 000000000..4df13b70e --- /dev/null +++ b/cmd/helm/testdata/output/install-no-hooks.txt @@ -0,0 +1,5 @@ +NAME: aeneas +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/install-with-multiple-values-files.txt b/cmd/helm/testdata/output/install-with-multiple-values-files.txt new file mode 100644 index 000000000..4f3c82375 --- /dev/null +++ b/cmd/helm/testdata/output/install-with-multiple-values-files.txt @@ -0,0 +1,5 @@ +NAME: virgil +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/install-with-multiple-values.txt b/cmd/helm/testdata/output/install-with-multiple-values.txt new file mode 100644 index 000000000..4f3c82375 --- /dev/null +++ b/cmd/helm/testdata/output/install-with-multiple-values.txt @@ -0,0 +1,5 @@ +NAME: virgil +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/install-with-timeout.txt b/cmd/helm/testdata/output/install-with-timeout.txt new file mode 100644 index 000000000..dfa30eed0 --- /dev/null +++ b/cmd/helm/testdata/output/install-with-timeout.txt @@ -0,0 +1,5 @@ +NAME: foobar +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/install-with-values-file.txt b/cmd/helm/testdata/output/install-with-values-file.txt new file mode 100644 index 000000000..4f3c82375 --- /dev/null +++ b/cmd/helm/testdata/output/install-with-values-file.txt @@ -0,0 +1,5 @@ +NAME: virgil +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/install-with-values.txt b/cmd/helm/testdata/output/install-with-values.txt new file mode 100644 index 000000000..4f3c82375 --- /dev/null +++ b/cmd/helm/testdata/output/install-with-values.txt @@ -0,0 +1,5 @@ +NAME: virgil +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/install-with-wait.txt b/cmd/helm/testdata/output/install-with-wait.txt new file mode 100644 index 000000000..1955d4714 --- /dev/null +++ b/cmd/helm/testdata/output/install-with-wait.txt @@ -0,0 +1,5 @@ +NAME: apollo +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/install.txt b/cmd/helm/testdata/output/install.txt new file mode 100644 index 000000000..4df13b70e --- /dev/null +++ b/cmd/helm/testdata/output/install.txt @@ -0,0 +1,5 @@ +NAME: aeneas +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/list-with-failed.txt b/cmd/helm/testdata/output/list-with-failed.txt new file mode 100644 index 000000000..289dcac23 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-failed.txt @@ -0,0 +1,2 @@ +thomas-guide +atlas-guide diff --git a/cmd/helm/testdata/output/list-with-mulitple-flags-deleting.txt b/cmd/helm/testdata/output/list-with-mulitple-flags-deleting.txt new file mode 100644 index 000000000..289dcac23 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-mulitple-flags-deleting.txt @@ -0,0 +1,2 @@ +thomas-guide +atlas-guide diff --git a/cmd/helm/testdata/output/list-with-mulitple-flags-namespaced.txt b/cmd/helm/testdata/output/list-with-mulitple-flags-namespaced.txt new file mode 100644 index 000000000..289dcac23 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-mulitple-flags-namespaced.txt @@ -0,0 +1,2 @@ +thomas-guide +atlas-guide diff --git a/cmd/helm/testdata/output/list-with-mulitple-flags-pending.txt b/cmd/helm/testdata/output/list-with-mulitple-flags-pending.txt new file mode 100644 index 000000000..289dcac23 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-mulitple-flags-pending.txt @@ -0,0 +1,2 @@ +thomas-guide +atlas-guide diff --git a/cmd/helm/testdata/output/list-with-mulitple-flags.txt b/cmd/helm/testdata/output/list-with-mulitple-flags.txt new file mode 100644 index 000000000..289dcac23 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-mulitple-flags.txt @@ -0,0 +1,2 @@ +thomas-guide +atlas-guide diff --git a/cmd/helm/testdata/output/list-with-mulitple-flags2.txt b/cmd/helm/testdata/output/list-with-mulitple-flags2.txt new file mode 100644 index 000000000..289dcac23 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-mulitple-flags2.txt @@ -0,0 +1,2 @@ +thomas-guide +atlas-guide diff --git a/cmd/helm/testdata/output/list-with-namespace.txt b/cmd/helm/testdata/output/list-with-namespace.txt new file mode 100644 index 000000000..289dcac23 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-namespace.txt @@ -0,0 +1,2 @@ +thomas-guide +atlas-guide diff --git a/cmd/helm/testdata/output/list-with-old-releases.txt b/cmd/helm/testdata/output/list-with-old-releases.txt new file mode 100644 index 000000000..76a90e3b2 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-old-releases.txt @@ -0,0 +1,3 @@ +NAME REVISION UPDATED STATUS CHART NAMESPACE +thomas-guide 1 1977-09-02 22:04:05 +0000 UTC deployed foo-0.1.0-beta.1 default +thomas-guide 1 1977-09-02 22:04:05 +0000 UTC failed foo-0.1.0-beta.1 default diff --git a/cmd/helm/testdata/output/list-with-pending.txt b/cmd/helm/testdata/output/list-with-pending.txt new file mode 100644 index 000000000..9a5953f48 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-pending.txt @@ -0,0 +1,4 @@ +thomas-guide +wild-idea +crazy-maps +atlas-guide diff --git a/cmd/helm/testdata/output/list-with-release.txt b/cmd/helm/testdata/output/list-with-release.txt new file mode 100644 index 000000000..11b3397b5 --- /dev/null +++ b/cmd/helm/testdata/output/list-with-release.txt @@ -0,0 +1,2 @@ +NAME REVISION UPDATED STATUS CHART NAMESPACE +thomas-guide 1 1977-09-02 22:04:05 +0000 UTC deployed foo-0.1.0-beta.1 default diff --git a/cmd/helm/testdata/output/list.txt b/cmd/helm/testdata/output/list.txt new file mode 100644 index 000000000..819f60f6d --- /dev/null +++ b/cmd/helm/testdata/output/list.txt @@ -0,0 +1,2 @@ +NAME REVISION UPDATED STATUS CHART NAMESPACE +atlas 1 1977-09-02 22:04:05 +0000 UTC deployed foo-0.1.0-beta.1 default diff --git a/cmd/helm/testdata/output/repo-add.txt b/cmd/helm/testdata/output/repo-add.txt new file mode 100644 index 000000000..e8882321e --- /dev/null +++ b/cmd/helm/testdata/output/repo-add.txt @@ -0,0 +1 @@ +"test-name" has been added to your repositories diff --git a/cmd/helm/testdata/output/rollback-no-args.txt b/cmd/helm/testdata/output/rollback-no-args.txt new file mode 100644 index 000000000..7d36e31af --- /dev/null +++ b/cmd/helm/testdata/output/rollback-no-args.txt @@ -0,0 +1 @@ +Error: This command needs 2 arguments: release name, revision number diff --git a/cmd/helm/testdata/output/rollback-timeout.txt b/cmd/helm/testdata/output/rollback-timeout.txt new file mode 100644 index 000000000..ae3c6f1c4 --- /dev/null +++ b/cmd/helm/testdata/output/rollback-timeout.txt @@ -0,0 +1 @@ +Rollback was a success! Happy Helming! diff --git a/cmd/helm/testdata/output/rollback-wait.txt b/cmd/helm/testdata/output/rollback-wait.txt new file mode 100644 index 000000000..ae3c6f1c4 --- /dev/null +++ b/cmd/helm/testdata/output/rollback-wait.txt @@ -0,0 +1 @@ +Rollback was a success! Happy Helming! diff --git a/cmd/helm/testdata/output/rollback.txt b/cmd/helm/testdata/output/rollback.txt new file mode 100644 index 000000000..ae3c6f1c4 --- /dev/null +++ b/cmd/helm/testdata/output/rollback.txt @@ -0,0 +1 @@ +Rollback was a success! Happy Helming! diff --git a/cmd/helm/testdata/output/search-constraint-single.txt b/cmd/helm/testdata/output/search-constraint-single.txt new file mode 100644 index 000000000..a1f75099f --- /dev/null +++ b/cmd/helm/testdata/output/search-constraint-single.txt @@ -0,0 +1,2 @@ +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-constraint.txt b/cmd/helm/testdata/output/search-constraint.txt new file mode 100644 index 000000000..9fb22fe76 --- /dev/null +++ b/cmd/helm/testdata/output/search-constraint.txt @@ -0,0 +1,2 @@ +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-multiple-versions-constraints.txt b/cmd/helm/testdata/output/search-multiple-versions-constraints.txt new file mode 100644 index 000000000..a6a388858 --- /dev/null +++ b/cmd/helm/testdata/output/search-multiple-versions-constraints.txt @@ -0,0 +1,3 @@ +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-multiple-versions.txt b/cmd/helm/testdata/output/search-multiple-versions.txt new file mode 100644 index 000000000..a6a388858 --- /dev/null +++ b/cmd/helm/testdata/output/search-multiple-versions.txt @@ -0,0 +1,3 @@ +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-multiple.txt b/cmd/helm/testdata/output/search-multiple.txt new file mode 100644 index 000000000..a1f75099f --- /dev/null +++ b/cmd/helm/testdata/output/search-multiple.txt @@ -0,0 +1,2 @@ +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-not-found.txt b/cmd/helm/testdata/output/search-not-found.txt new file mode 100644 index 000000000..4f2a9fd07 --- /dev/null +++ b/cmd/helm/testdata/output/search-not-found.txt @@ -0,0 +1 @@ +No results found diff --git a/cmd/helm/testdata/output/search-regex.txt b/cmd/helm/testdata/output/search-regex.txt new file mode 100644 index 000000000..a1f75099f --- /dev/null +++ b/cmd/helm/testdata/output/search-regex.txt @@ -0,0 +1,2 @@ +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.2.0 2.3.4 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/search-single.txt b/cmd/helm/testdata/output/search-single.txt new file mode 100644 index 000000000..936605ae1 --- /dev/null +++ b/cmd/helm/testdata/output/search-single.txt @@ -0,0 +1,2 @@ +NAME CHART VERSION APP VERSION DESCRIPTION +testing/mariadb 0.3.0 Chart for MariaDB diff --git a/cmd/helm/testdata/output/search-versions-constraint.txt b/cmd/helm/testdata/output/search-versions-constraint.txt new file mode 100644 index 000000000..9fb22fe76 --- /dev/null +++ b/cmd/helm/testdata/output/search-versions-constraint.txt @@ -0,0 +1,2 @@ +NAME CHART VERSION APP VERSION DESCRIPTION +testing/alpine 0.1.0 1.2.3 Deploy a basic Alpine Linux pod diff --git a/cmd/helm/testdata/output/status-with-notes.txt b/cmd/helm/testdata/output/status-with-notes.txt new file mode 100644 index 000000000..280855bc7 --- /dev/null +++ b/cmd/helm/testdata/output/status-with-notes.txt @@ -0,0 +1,6 @@ +LAST DEPLOYED: 2016-01-16 00:00:00 +0000 UTC +NAMESPACE: +STATUS: deployed + +NOTES: +release notes diff --git a/cmd/helm/testdata/output/status-with-resource.txt b/cmd/helm/testdata/output/status-with-resource.txt new file mode 100644 index 000000000..ec2d9f8e6 --- /dev/null +++ b/cmd/helm/testdata/output/status-with-resource.txt @@ -0,0 +1,8 @@ +LAST DEPLOYED: 2016-01-16 00:00:00 +0000 UTC +NAMESPACE: +STATUS: deployed + +RESOURCES: +resource A +resource B + diff --git a/cmd/helm/testdata/output/status-with-test-suite.txt b/cmd/helm/testdata/output/status-with-test-suite.txt new file mode 100644 index 000000000..63012498a --- /dev/null +++ b/cmd/helm/testdata/output/status-with-test-suite.txt @@ -0,0 +1,11 @@ +LAST DEPLOYED: 2016-01-16 00:00:00 +0000 UTC +NAMESPACE: +STATUS: deployed + +TEST SUITE: +Last Started: 0001-01-01 00:00:00 +0000 UTC +Last Completed: 0001-01-01 00:00:00 +0000 UTC + +TEST STATUS INFO STARTED COMPLETED +test run 1 success extra info 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC +test run 2 failure 0001-01-01 00:00:00 +0000 UTC 0001-01-01 00:00:00 +0000 UTC diff --git a/cmd/helm/testdata/output/status.json b/cmd/helm/testdata/output/status.json new file mode 100644 index 000000000..aee9340d3 --- /dev/null +++ b/cmd/helm/testdata/output/status.json @@ -0,0 +1 @@ +{"name":"flummoxed-chickadee","info":{"first_deployed":"0001-01-01T00:00:00Z","last_deployed":"2016-01-16T00:00:00Z","deleted":"0001-01-01T00:00:00Z","status":"deployed","notes":"release notes"}} \ No newline at end of file diff --git a/cmd/helm/testdata/output/status.txt b/cmd/helm/testdata/output/status.txt new file mode 100644 index 000000000..7ac60bede --- /dev/null +++ b/cmd/helm/testdata/output/status.txt @@ -0,0 +1,4 @@ +LAST DEPLOYED: 2016-01-16 00:00:00 +0000 UTC +NAMESPACE: +STATUS: deployed + diff --git a/cmd/helm/testdata/output/status.yaml b/cmd/helm/testdata/output/status.yaml new file mode 100644 index 000000000..a3990a954 --- /dev/null +++ b/cmd/helm/testdata/output/status.yaml @@ -0,0 +1,9 @@ +info: + deleted: 0001-01-01T00:00:00Z + first_deployed: 0001-01-01T00:00:00Z + last_deployed: 2016-01-16T00:00:00Z + resources: | + resource A + resource B + status: deployed +name: flummoxed-chickadee diff --git a/cmd/helm/testdata/output/test-error.txt b/cmd/helm/testdata/output/test-error.txt new file mode 100644 index 000000000..8a80a0492 --- /dev/null +++ b/cmd/helm/testdata/output/test-error.txt @@ -0,0 +1,2 @@ +ERROR: yellow lights everywhere +Error: 1 test(s) failed diff --git a/cmd/helm/testdata/output/test-failure.txt b/cmd/helm/testdata/output/test-failure.txt new file mode 100644 index 000000000..aed8bd8c3 --- /dev/null +++ b/cmd/helm/testdata/output/test-failure.txt @@ -0,0 +1,2 @@ +FAILURE: red lights everywhere +Error: 1 test(s) failed diff --git a/cmd/helm/testdata/output/test-running.txt b/cmd/helm/testdata/output/test-running.txt new file mode 100644 index 000000000..da4e5e285 --- /dev/null +++ b/cmd/helm/testdata/output/test-running.txt @@ -0,0 +1 @@ +RUNNING: things are happpeningggg diff --git a/cmd/helm/testdata/output/test-unknown.txt b/cmd/helm/testdata/output/test-unknown.txt new file mode 100644 index 000000000..0003f3d25 --- /dev/null +++ b/cmd/helm/testdata/output/test-unknown.txt @@ -0,0 +1 @@ +UNKNOWN: yellow lights everywhere diff --git a/cmd/helm/testdata/output/test.txt b/cmd/helm/testdata/output/test.txt new file mode 100644 index 000000000..26876ac88 --- /dev/null +++ b/cmd/helm/testdata/output/test.txt @@ -0,0 +1 @@ +PASSED: green lights everywhere diff --git a/cmd/helm/testdata/output/upgrade-with-bad-dependencies.txt b/cmd/helm/testdata/output/upgrade-with-bad-dependencies.txt new file mode 100644 index 000000000..c77fba18b --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-with-bad-dependencies.txt @@ -0,0 +1 @@ +Error: cannot load requirements: error converting YAML to JSON: yaml: line 2: did not find expected '-' indicator diff --git a/cmd/helm/testdata/output/upgrade-with-install-timeout.txt b/cmd/helm/testdata/output/upgrade-with-install-timeout.txt new file mode 100644 index 000000000..4a2233228 --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-with-install-timeout.txt @@ -0,0 +1,49 @@ +REVISION: 1 +RELEASED: Fri Sep 2 22:04:05 1977 +CHART: testUpgradeChart-0.1.0 +USER-SUPPLIED VALUES: +name: "value" +COMPUTED VALUES: +affinity: {} +fullnameOverride: "" +image: + pullPolicy: IfNotPresent + repository: nginx + tag: stable +ingress: + annotations: {} + enabled: false + hosts: + - chart-example.local + path: / + tls: [] +name: value +nameOverride: "" +nodeSelector: {} +replicaCount: 1 +resources: {} +service: + port: 80 + type: ClusterIP +tolerations: [] + +HOOKS: +--- +# pre-install-hook +apiVersion: v1 +kind: Job +metadata: + annotations: + "helm.sh/hook": pre-install + +MANIFEST: +apiVersion: v1 +kind: Secret +metadata: + name: fixture + +Release "crazy-bunny" has been upgraded. Happy Helming! +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/upgrade-with-install.txt b/cmd/helm/testdata/output/upgrade-with-install.txt new file mode 100644 index 000000000..90d69d65f --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-with-install.txt @@ -0,0 +1,49 @@ +REVISION: 1 +RELEASED: Fri Sep 2 22:04:05 1977 +CHART: testUpgradeChart-0.1.0 +USER-SUPPLIED VALUES: +name: "value" +COMPUTED VALUES: +affinity: {} +fullnameOverride: "" +image: + pullPolicy: IfNotPresent + repository: nginx + tag: stable +ingress: + annotations: {} + enabled: false + hosts: + - chart-example.local + path: / + tls: [] +name: value +nameOverride: "" +nodeSelector: {} +replicaCount: 1 +resources: {} +service: + port: 80 + type: ClusterIP +tolerations: [] + +HOOKS: +--- +# pre-install-hook +apiVersion: v1 +kind: Job +metadata: + annotations: + "helm.sh/hook": pre-install + +MANIFEST: +apiVersion: v1 +kind: Secret +metadata: + name: fixture + +Release "zany-bunny" has been upgraded. Happy Helming! +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/upgrade-with-missing-dependencies.txt b/cmd/helm/testdata/output/upgrade-with-missing-dependencies.txt new file mode 100644 index 000000000..4325478d7 --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-with-missing-dependencies.txt @@ -0,0 +1 @@ +Error: This command needs 2 arguments: release name, chart path diff --git a/cmd/helm/testdata/output/upgrade-with-reset-values.txt b/cmd/helm/testdata/output/upgrade-with-reset-values.txt new file mode 100644 index 000000000..4e5989e7f --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-with-reset-values.txt @@ -0,0 +1,49 @@ +REVISION: 4 +RELEASED: Fri Sep 2 22:04:05 1977 +CHART: testUpgradeChart-0.1.0 +USER-SUPPLIED VALUES: +name: "value" +COMPUTED VALUES: +affinity: {} +fullnameOverride: "" +image: + pullPolicy: IfNotPresent + repository: nginx + tag: stable +ingress: + annotations: {} + enabled: false + hosts: + - chart-example.local + path: / + tls: [] +name: value +nameOverride: "" +nodeSelector: {} +replicaCount: 1 +resources: {} +service: + port: 80 + type: ClusterIP +tolerations: [] + +HOOKS: +--- +# pre-install-hook +apiVersion: v1 +kind: Job +metadata: + annotations: + "helm.sh/hook": pre-install + +MANIFEST: +apiVersion: v1 +kind: Secret +metadata: + name: fixture + +Release "funny-bunny" has been upgraded. Happy Helming! +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/upgrade-with-reset-values2.txt b/cmd/helm/testdata/output/upgrade-with-reset-values2.txt new file mode 100644 index 000000000..12c5d47a8 --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-with-reset-values2.txt @@ -0,0 +1,49 @@ +REVISION: 5 +RELEASED: Fri Sep 2 22:04:05 1977 +CHART: testUpgradeChart-0.1.0 +USER-SUPPLIED VALUES: +name: "value" +COMPUTED VALUES: +affinity: {} +fullnameOverride: "" +image: + pullPolicy: IfNotPresent + repository: nginx + tag: stable +ingress: + annotations: {} + enabled: false + hosts: + - chart-example.local + path: / + tls: [] +name: value +nameOverride: "" +nodeSelector: {} +replicaCount: 1 +resources: {} +service: + port: 80 + type: ClusterIP +tolerations: [] + +HOOKS: +--- +# pre-install-hook +apiVersion: v1 +kind: Job +metadata: + annotations: + "helm.sh/hook": pre-install + +MANIFEST: +apiVersion: v1 +kind: Secret +metadata: + name: fixture + +Release "funny-bunny" has been upgraded. Happy Helming! +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/upgrade-with-timeout.txt b/cmd/helm/testdata/output/upgrade-with-timeout.txt new file mode 100644 index 000000000..156fa5951 --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-with-timeout.txt @@ -0,0 +1,49 @@ +REVISION: 3 +RELEASED: Fri Sep 2 22:04:05 1977 +CHART: testUpgradeChart-0.1.0 +USER-SUPPLIED VALUES: +name: "value" +COMPUTED VALUES: +affinity: {} +fullnameOverride: "" +image: + pullPolicy: IfNotPresent + repository: nginx + tag: stable +ingress: + annotations: {} + enabled: false + hosts: + - chart-example.local + path: / + tls: [] +name: value +nameOverride: "" +nodeSelector: {} +replicaCount: 1 +resources: {} +service: + port: 80 + type: ClusterIP +tolerations: [] + +HOOKS: +--- +# pre-install-hook +apiVersion: v1 +kind: Job +metadata: + annotations: + "helm.sh/hook": pre-install + +MANIFEST: +apiVersion: v1 +kind: Secret +metadata: + name: fixture + +Release "funny-bunny" has been upgraded. Happy Helming! +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/upgrade-with-wait.txt b/cmd/helm/testdata/output/upgrade-with-wait.txt new file mode 100644 index 000000000..092c813a2 --- /dev/null +++ b/cmd/helm/testdata/output/upgrade-with-wait.txt @@ -0,0 +1,49 @@ +REVISION: 2 +RELEASED: Fri Sep 2 22:04:05 1977 +CHART: testUpgradeChart-0.1.0 +USER-SUPPLIED VALUES: +name: "value" +COMPUTED VALUES: +affinity: {} +fullnameOverride: "" +image: + pullPolicy: IfNotPresent + repository: nginx + tag: stable +ingress: + annotations: {} + enabled: false + hosts: + - chart-example.local + path: / + tls: [] +name: value +nameOverride: "" +nodeSelector: {} +replicaCount: 1 +resources: {} +service: + port: 80 + type: ClusterIP +tolerations: [] + +HOOKS: +--- +# pre-install-hook +apiVersion: v1 +kind: Job +metadata: + annotations: + "helm.sh/hook": pre-install + +MANIFEST: +apiVersion: v1 +kind: Secret +metadata: + name: fixture + +Release "crazy-bunny" has been upgraded. Happy Helming! +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/upgrade.txt b/cmd/helm/testdata/output/upgrade.txt new file mode 100644 index 000000000..2a31c7ea7 --- /dev/null +++ b/cmd/helm/testdata/output/upgrade.txt @@ -0,0 +1,49 @@ +REVISION: 2 +RELEASED: Fri Sep 2 22:04:05 1977 +CHART: testUpgradeChart-0.1.0 +USER-SUPPLIED VALUES: +name: "value" +COMPUTED VALUES: +affinity: {} +fullnameOverride: "" +image: + pullPolicy: IfNotPresent + repository: nginx + tag: stable +ingress: + annotations: {} + enabled: false + hosts: + - chart-example.local + path: / + tls: [] +name: value +nameOverride: "" +nodeSelector: {} +replicaCount: 1 +resources: {} +service: + port: 80 + type: ClusterIP +tolerations: [] + +HOOKS: +--- +# pre-install-hook +apiVersion: v1 +kind: Job +metadata: + annotations: + "helm.sh/hook": pre-install + +MANIFEST: +apiVersion: v1 +kind: Secret +metadata: + name: fixture + +Release "funny-bunny" has been upgraded. Happy Helming! +LAST DEPLOYED: 1977-09-02 22:04:05 +0000 UTC +NAMESPACE: default +STATUS: deployed + diff --git a/cmd/helm/testdata/output/version-template.txt b/cmd/helm/testdata/output/version-template.txt new file mode 100644 index 000000000..c12e29c2d --- /dev/null +++ b/cmd/helm/testdata/output/version-template.txt @@ -0,0 +1 @@ +Version: v3.0+unreleased \ No newline at end of file diff --git a/cmd/helm/testdata/output/version.txt b/cmd/helm/testdata/output/version.txt new file mode 100644 index 000000000..9cc619059 --- /dev/null +++ b/cmd/helm/testdata/output/version.txt @@ -0,0 +1 @@ +version.BuildInfo{Version:"v3.0+unreleased", GitCommit:"", GitTreeState:""} diff --git a/cmd/helm/testdata/testcache/foobar-index.yaml b/cmd/helm/testdata/testcache/foobar-index.yaml deleted file mode 100644 index b8083fd06..000000000 --- a/cmd/helm/testdata/testcache/foobar-index.yaml +++ /dev/null @@ -1,24 +0,0 @@ -foobar-0.1.0: - url: https://kubernetes-charts.storage.googleapis.com/nginx-0.1.0.tgz - name: foobar - removed: false - chartfile: - name: foobar - description: string - version: 0.1.0 - home: https://github.com/foo - keywords: - - dummy - - hokey -oddness-1.2.3: - url: https://kubernetes-charts.storage.googleapis.com/alpine-1.0.0.tgz - name: oddness - removed: false - chartfile: - name: oddness - description: string - version: 1.2.3 - home: https://github.com/something - keywords: - - duck - - sumtin diff --git a/cmd/helm/testdata/testcache/local-index.yaml b/cmd/helm/testdata/testcache/local-index.yaml deleted file mode 100644 index a589e2321..000000000 --- a/cmd/helm/testdata/testcache/local-index.yaml +++ /dev/null @@ -1,27 +0,0 @@ -nginx-0.1.0: - url: https://kubernetes-charts.storage.googleapis.com/nginx-0.1.0.tgz - name: nginx - removed: false - chartfile: - name: nginx - description: string - version: 0.1.0 - home: https://github.com/something - keywords: - - popular - - web server - - proxy -alpine-1.0.0: - url: https://kubernetes-charts.storage.googleapis.com/alpine-1.0.0.tgz - name: alpine - removed: false - chartfile: - name: alpine - description: string - version: 1.0.0 - home: https://github.com/something - keywords: - - linux - - alpine - - small - - sumtin diff --git a/cmd/helm/upgrade_test.go b/cmd/helm/upgrade_test.go index eb5d7b011..4b689297e 100644 --- a/cmd/helm/upgrade_test.go +++ b/cmd/helm/upgrade_test.go @@ -79,14 +79,8 @@ func TestUpgradeCmd(t *testing.T) { t.Errorf("Error loading updated chart: %v", err) } - originalDepsPath := filepath.Join("testdata/testcharts/reqtest") missingDepsPath := filepath.Join("testdata/testcharts/chart-missing-deps") badDepsPath := filepath.Join("testdata/testcharts/chart-bad-requirements") - var ch3 *chart.Chart - ch3, err = chartutil.Load(originalDepsPath) - if err != nil { - t.Errorf("Error loading chart with missing dependencies: %v", err) - } relMock := func(n string, v int, ch *chart.Chart) *release.Release { return helm.ReleaseMock(&helm.MockReleaseOptions{Name: n, Version: v, Chart: ch}) @@ -94,67 +88,59 @@ func TestUpgradeCmd(t *testing.T) { tests := []releaseCase{ { - name: "upgrade a release", - cmd: "upgrade funny-bunny " + chartPath, - resp: relMock("funny-bunny", 2, ch), - matches: "Release \"funny-bunny\" has been upgraded. Happy Helming!\n", - rels: []*release.Release{relMock("funny-bunny", 2, ch)}, + name: "upgrade a release", + cmd: "upgrade funny-bunny " + chartPath, + golden: "output/upgrade.txt", + rels: []*release.Release{relMock("funny-bunny", 2, ch)}, }, { - name: "upgrade a release with timeout", - cmd: "upgrade funny-bunny --timeout 120 " + chartPath, - resp: relMock("funny-bunny", 3, ch2), - matches: "Release \"funny-bunny\" has been upgraded. Happy Helming!\n", - rels: []*release.Release{relMock("funny-bunny", 3, ch2)}, + name: "upgrade a release with timeout", + cmd: "upgrade funny-bunny --timeout 120 " + chartPath, + golden: "output/upgrade-with-timeout.txt", + rels: []*release.Release{relMock("funny-bunny", 3, ch2)}, }, { - name: "upgrade a release with --reset-values", - cmd: "upgrade funny-bunny --reset-values " + chartPath, - resp: relMock("funny-bunny", 4, ch2), - matches: "Release \"funny-bunny\" has been upgraded. Happy Helming!\n", - rels: []*release.Release{relMock("funny-bunny", 4, ch2)}, + name: "upgrade a release with --reset-values", + cmd: "upgrade funny-bunny --reset-values " + chartPath, + golden: "output/upgrade-with-reset-values.txt", + rels: []*release.Release{relMock("funny-bunny", 4, ch2)}, }, { - name: "upgrade a release with --reuse-values", - cmd: "upgrade funny-bunny --reuse-values " + chartPath, - resp: relMock("funny-bunny", 5, ch2), - matches: "Release \"funny-bunny\" has been upgraded. Happy Helming!\n", - rels: []*release.Release{relMock("funny-bunny", 5, ch2)}, + name: "upgrade a release with --reuse-values", + cmd: "upgrade funny-bunny --reuse-values " + chartPath, + golden: "output/upgrade-with-reset-values2.txt", + rels: []*release.Release{relMock("funny-bunny", 5, ch2)}, }, { - name: "install a release with 'upgrade --install'", - cmd: "upgrade zany-bunny -i " + chartPath, - resp: relMock("zany-bunny", 1, ch), - matches: "Release \"zany-bunny\" has been upgraded. Happy Helming!\n", - rels: []*release.Release{relMock("zany-bunny", 1, ch)}, + name: "install a release with 'upgrade --install'", + cmd: "upgrade zany-bunny -i " + chartPath, + golden: "output/upgrade-with-install.txt", + rels: []*release.Release{relMock("zany-bunny", 1, ch)}, }, { - name: "install a release with 'upgrade --install' and timeout", - cmd: "upgrade crazy-bunny -i --timeout 120 " + chartPath, - resp: relMock("crazy-bunny", 1, ch), - matches: "Release \"crazy-bunny\" has been upgraded. Happy Helming!\n", - rels: []*release.Release{relMock("crazy-bunny", 1, ch)}, + name: "install a release with 'upgrade --install' and timeout", + cmd: "upgrade crazy-bunny -i --timeout 120 " + chartPath, + golden: "output/upgrade-with-install-timeout.txt", + rels: []*release.Release{relMock("crazy-bunny", 1, ch)}, }, { - name: "upgrade a release with wait", - cmd: "upgrade crazy-bunny --wait " + chartPath, - resp: relMock("crazy-bunny", 2, ch2), - matches: "Release \"crazy-bunny\" has been upgraded. Happy Helming!\n", - rels: []*release.Release{relMock("crazy-bunny", 2, ch2)}, + name: "upgrade a release with wait", + cmd: "upgrade crazy-bunny --wait " + chartPath, + golden: "output/upgrade-with-wait.txt", + rels: []*release.Release{relMock("crazy-bunny", 2, ch2)}, }, { name: "upgrade a release with missing dependencies", cmd: "upgrade bonkers-bunny" + missingDepsPath, - resp: relMock("bonkers-bunny", 1, ch3), + golden: "output/upgrade-with-missing-dependencies.txt", wantError: true, }, { name: "upgrade a release with bad dependencies", cmd: "upgrade bonkers-bunny " + badDepsPath, - resp: relMock("bonkers-bunny", 1, ch3), + golden: "output/upgrade-with-bad-dependencies.txt", wantError: true, }, } testReleaseCmd(t, tests) - } diff --git a/cmd/helm/verify_test.go b/cmd/helm/verify_test.go index 6e8b906fc..7ae98742c 100644 --- a/cmd/helm/verify_test.go +++ b/cmd/helm/verify_test.go @@ -16,7 +16,6 @@ limitations under the License. package main import ( - "bytes" "fmt" "runtime" "testing" @@ -34,62 +33,60 @@ func TestVerifyCmd(t *testing.T) { } tests := []struct { - name string - args []string - flags []string - expect string - err bool + name string + cmd string + expect string + wantError bool }{ { - name: "verify requires a chart", - expect: "a path to a package file is required", - err: true, + name: "verify requires a chart", + cmd: "verify", + expect: "a path to a package file is required", + wantError: true, }, { - name: "verify requires that chart exists", - args: []string{"no/such/file"}, - expect: fmt.Sprintf("%s no/such/file: %s", statExe, statPathMsg), - err: true, + name: "verify requires that chart exists", + cmd: "verify no/such/file", + expect: fmt.Sprintf("%s no/such/file: %s", statExe, statPathMsg), + wantError: true, }, { - name: "verify requires that chart is not a directory", - args: []string{"testdata/testcharts/signtest"}, - expect: "unpacked charts cannot be verified", - err: true, + name: "verify requires that chart is not a directory", + cmd: "verify testdata/testcharts/signtest", + expect: "unpacked charts cannot be verified", + wantError: true, }, { - name: "verify requires that chart has prov file", - args: []string{"testdata/testcharts/compressedchart-0.1.0.tgz"}, - expect: fmt.Sprintf("could not load provenance file testdata/testcharts/compressedchart-0.1.0.tgz.prov: %s testdata/testcharts/compressedchart-0.1.0.tgz.prov: %s", statExe, statFileMsg), - err: true, + name: "verify requires that chart has prov file", + cmd: "verify testdata/testcharts/compressedchart-0.1.0.tgz", + expect: fmt.Sprintf("could not load provenance file testdata/testcharts/compressedchart-0.1.0.tgz.prov: %s testdata/testcharts/compressedchart-0.1.0.tgz.prov: %s", statExe, statFileMsg), + wantError: true, }, { - name: "verify validates a properly signed chart", - args: []string{"testdata/testcharts/signtest-0.1.0.tgz"}, - flags: []string{"--keyring", "testdata/helm-test-key.pub"}, - expect: "", - err: false, + name: "verify validates a properly signed chart", + cmd: "verify testdata/testcharts/signtest-0.1.0.tgz --keyring testdata/helm-test-key.pub", + expect: "", + wantError: false, }, } for _, tt := range tests { - b := bytes.NewBuffer(nil) - vc := newVerifyCmd(b) - vc.ParseFlags(tt.flags) - err := vc.RunE(vc, tt.args) - if tt.err { - if err == nil { - t.Errorf("Expected error, but got none: %q", b.String()) + t.Run(tt.name, func(t *testing.T) { + out, err := executeCommand(nil, tt.cmd) + if tt.wantError { + if err == nil { + t.Errorf("Expected error, but got none: %q", out) + } + if err.Error() != tt.expect { + t.Errorf("Expected error %q, got %q", tt.expect, err) + } + return + } else if err != nil { + t.Errorf("Unexpected error: %s", err) } - if err.Error() != tt.expect { - t.Errorf("Expected error %q, got %q", tt.expect, err) + if out != tt.expect { + t.Errorf("Expected %q, got %q", tt.expect, out) } - continue - } else if err != nil { - t.Errorf("Unexpected error: %s", err) - } - if b.String() != tt.expect { - t.Errorf("Expected %q, got %q", tt.expect, b.String()) - } + }) } } diff --git a/cmd/helm/version.go b/cmd/helm/version.go index 01d6a03b3..100259896 100644 --- a/cmd/helm/version.go +++ b/cmd/helm/version.go @@ -19,6 +19,7 @@ package main import ( "fmt" "io" + "text/template" "github.com/spf13/cobra" @@ -31,7 +32,7 @@ Show the version for Helm. This will print a representation the version of Helm. The output will look something like this: -Client: &version.BuildInfo{Version:"v2.0.0", GitCommit:"ff52399e51bb880526e9cd0ed8386f6433b74da1", GitTreeState:"clean"} +version.BuildInfo{Version:"v2.0.0", GitCommit:"ff52399e51bb880526e9cd0ed8386f6433b74da1", GitTreeState:"clean"} - Version is the semantic version of the release. - GitCommit is the SHA for the commit that this version was built from. @@ -64,19 +65,19 @@ func newVersionCmd(out io.Writer) *cobra.Command { } func (v *versionCmd) run() error { - // Store map data for template rendering - data := map[string]interface{}{} - - cv := version.GetBuildInfo() if v.template != "" { - data["Client"] = cv - return tpl(v.template, data, v.out) + tt, err := template.New("_").Parse(v.template) + if err != nil { + return err + } + return tt.Execute(v.out, version.GetBuildInfo()) } - fmt.Fprintf(v.out, "Client: %s\n", formatVersion(cv, v.short)) + fmt.Fprintln(v.out, formatVersion(v.short)) return nil } -func formatVersion(v *version.BuildInfo, short bool) string { +func formatVersion(short bool) string { + v := version.GetBuildInfo() if short { return fmt.Sprintf("%s+g%s", v.Version, v.GitCommit[:7]) } diff --git a/cmd/helm/version_test.go b/cmd/helm/version_test.go index b5b91dec7..166b78f93 100644 --- a/cmd/helm/version_test.go +++ b/cmd/helm/version_test.go @@ -16,28 +16,18 @@ limitations under the License. package main import ( - "fmt" - "regexp" "testing" - - "k8s.io/helm/pkg/version" ) func TestVersion(t *testing.T) { - lver := regexp.QuoteMeta(version.GetVersion()) - clientVersion := fmt.Sprintf("Client: &version\\.BuildInfo{Version:\"%s\", GitCommit:\"\", GitTreeState:\"\"}\n", lver) - - tests := []releaseCase{ - { - name: "default", - cmd: "version", - matches: clientVersion, - }, - { - name: "template", - cmd: "version --template='{{.Client.Version}}'", - matches: lver, - }, - } + tests := []releaseCase{{ + name: "default", + cmd: "version", + golden: "output/version.txt", + }, { + name: "template", + cmd: "version --template='Version: {{.Version}}'", + golden: "output/version-template.txt", + }} testReleaseCmd(t, tests) } diff --git a/internal/test/test.go b/internal/test/test.go new file mode 100644 index 000000000..6dbff7b90 --- /dev/null +++ b/internal/test/test.go @@ -0,0 +1,88 @@ +/* +Copyright 2018 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package test + +import ( + "bytes" + "flag" + "io/ioutil" + "path/filepath" + + "github.com/pkg/errors" +) + +// UpdateGolden writes out the golden files with the latest values, rather than failing the test. +var updateGolden = flag.Bool("update", false, "update golden files") + +type TestingT interface { + Fatal(...interface{}) + Fatalf(string, ...interface{}) + HelperT +} + +type HelperT interface { + Helper() +} + +func AssertGoldenBytes(t TestingT, actual []byte, filename string) { + t.Helper() + + if err := compare(actual, path(filename)); err != nil { + t.Fatalf("%+v", err) + } +} + +func AssertGoldenString(t TestingT, actual, filename string) { + t.Helper() + + if err := compare([]byte(actual), path(filename)); err != nil { + t.Fatalf("%+v", err) + } +} + +func path(filename string) string { + if filepath.IsAbs(filename) { + return filename + } + return filepath.Join("testdata", filename) +} + +func compare(actual []byte, filename string) error { + if err := update(filename, actual); err != nil { + return err + } + + expected, err := ioutil.ReadFile(filename) + if err != nil { + return errors.Wrapf(err, "unable to read testdata %s", filename) + } + if !bytes.Equal(expected, actual) { + return errors.Errorf("does not match golden file %s\n\nWANT:\n%q\n\nGOT:\n%q\n", filename, expected, actual) + } + return nil +} + +func update(filename string, in []byte) error { + if !*updateGolden { + return nil + } + return ioutil.WriteFile(filename, normalize(in), 0666) +} + +func normalize(in []byte) []byte { + return bytes.Replace(in, []byte("\r\n"), []byte("\n"), -1) +} diff --git a/pkg/chartutil/capabilities.go b/pkg/chartutil/capabilities.go index d208df005..06c117315 100644 --- a/pkg/chartutil/capabilities.go +++ b/pkg/chartutil/capabilities.go @@ -48,7 +48,7 @@ type Capabilities struct { // HelmVersion is the Helm version // // This always comes from pkg/version.BuildInfo(). - HelmVersion *tversion.BuildInfo + HelmVersion tversion.BuildInfo } // VersionSet is a set of Kubernetes API versions. diff --git a/pkg/hapi/chart/chart.go b/pkg/hapi/chart/chart.go index a74df58e6..711bee61d 100644 --- a/pkg/hapi/chart/chart.go +++ b/pkg/hapi/chart/chart.go @@ -15,18 +15,18 @@ limitations under the License. package chart -// Chart is a helm package that contains metadata, a default config, zero or more -// optionally parameterizable templates, and zero or more charts (dependencies). +// Chart is a helm package that contains metadata, a default config, zero or more +// optionally parameterizable templates, and zero or more charts (dependencies). type Chart struct { - // Contents of the Chartfile. + // Metadata is the contents of the Chartfile. Metadata *Metadata `json:"metadata,omitempty"` // Templates for this chart. Templates []*File `json:"templates,omitempty"` - // Charts that this chart depends on. + // Dependencies are the charts that this chart depends on. Dependencies []*Chart `json:"dependencies,omitempty"` - // Default config for this template. + // Values are default config for this template. Values []byte `json:"values,omitempty"` - // Miscellaneous files in a chart archive, + // Files are miscellaneous files in a chart archive, // e.g. README, LICENSE, etc. Files []*File `json:"files,omitempty"` } diff --git a/pkg/hapi/chart/metadata.go b/pkg/hapi/chart/metadata.go index bd55f94d3..dbd15ba08 100644 --- a/pkg/hapi/chart/metadata.go +++ b/pkg/hapi/chart/metadata.go @@ -21,13 +21,13 @@ type Maintainer struct { Name string `json:"name,omitempty"` // Email is an optional email address to contact the named maintainer Email string `json:"email,omitempty"` - // Url is an optional URL to an address for the named maintainer - Url string `json:"url,omitempty"` + // URL is an optional URL to an address for the named maintainer + URL string `json:"url,omitempty"` } -// Metadata for a Chart file. This models the structure of a Chart.yaml file. +// Metadata for a Chart file. This models the structure of a Chart.yaml file. // -// Spec: https://k8s.io/helm/blob/master/docs/design/chart_format.md#the-chart-file +// Spec: https://k8s.io/helm/blob/master/docs/design/chart_format.md#the-chart-file type Metadata struct { // The name of the chart Name string `json:"name,omitempty"` diff --git a/pkg/hapi/release/info.go b/pkg/hapi/release/info.go index 7572af12a..4b9a995d0 100644 --- a/pkg/hapi/release/info.go +++ b/pkg/hapi/release/info.go @@ -19,8 +19,10 @@ import "time" // Info describes release information. type Info struct { + // FirstDeployed is when the release was first deployed. FirstDeployed time.Time `json:"first_deployed,omitempty"` - LastDeployed time.Time `json:"last_deployed,omitempty"` + // LastDeployed is when the release was last deployed. + LastDeployed time.Time `json:"last_deployed,omitempty"` // Deleted tracks when this object was deleted. Deleted time.Time `json:"deleted,omitempty"` // Description is human-friendly "log entry" about this release. diff --git a/pkg/hapi/tiller.go b/pkg/hapi/tiller.go index 27cf290a8..ee30f5619 100644 --- a/pkg/hapi/tiller.go +++ b/pkg/hapi/tiller.go @@ -21,19 +21,23 @@ import ( ) // SortBy defines sort operations. -type ListSortBy string +type SortBy string const ( - ListSortName ListSortBy = "name" - ListSortLastReleased ListSortBy = "last-released" + // SortByName requests releases sorted by name. + SortByName SortBy = "name" + // SortByLastReleased requests releases sorted by last released. + SortByLastReleased SortBy = "last-released" ) // SortOrder defines sort orders to augment sorting operations. -type ListSortOrder string +type SortOrder string const ( - ListSortAsc ListSortOrder = "ascending" - ListSortDesc ListSortOrder = "descending" + //SortAsc defines ascending sorting. + SortAsc SortOrder = "ascending" + //SortDesc defines descending sorting. + SortDesc SortOrder = "descending" ) // ListReleasesRequest requests a list of releases. @@ -51,13 +55,13 @@ type ListReleasesRequest struct { // cause the next batch to return a set of results starting with 'dennis'. Offset string `json:"offset,omitempty"` // SortBy is the sort field that the ListReleases server should sort data before returning. - SortBy ListSortBy `json:"sort_by,omitempty"` + SortBy SortBy `json:"sort_by,omitempty"` // Filter is a regular expression used to filter which releases should be listed. // // Anything that matches the regexp will be included in the results. Filter string `json:"filter,omitempty"` // SortOrder is the ordering directive used for sorting. - SortOrder ListSortOrder `json:"sort_order,omitempty"` + SortOrder SortOrder `json:"sort_order,omitempty"` StatusCodes []release.ReleaseStatus `json:"status_codes,omitempty"` } @@ -115,6 +119,8 @@ type UpdateReleaseRequest struct { Force bool `json:"force,omitempty"` } +// RollbackReleaseRequest is the request for a release to be rolledback to a +// previous version. type RollbackReleaseRequest struct { // The name of the release Name string `json:"name,omitempty"` diff --git a/pkg/helm/fake.go b/pkg/helm/fake.go index 0095843d1..c5c399aa6 100644 --- a/pkg/helm/fake.go +++ b/pkg/helm/fake.go @@ -30,9 +30,9 @@ import ( // FakeClient implements Interface type FakeClient struct { - Rels []*release.Release - Responses map[string]release.TestRunStatus - Opts options + Rels []*release.Release + TestRunStatus map[string]release.TestRunStatus + Opts options } // Option returns the fake release client @@ -144,7 +144,7 @@ func (c *FakeClient) RunReleaseTest(rlsName string, opts ...ReleaseTestOption) ( go func() { var wg sync.WaitGroup - for m, s := range c.Responses { + for m, s := range c.TestRunStatus { wg.Add(1) go func(msg string, status release.TestRunStatus) { diff --git a/pkg/helm/helm_test.go b/pkg/helm/helm_test.go index 59cd99509..a2d44c610 100644 --- a/pkg/helm/helm_test.go +++ b/pkg/helm/helm_test.go @@ -40,8 +40,8 @@ func TestListReleases_VerifyOptions(t *testing.T) { var limit = 2 var offset = "offset" var filter = "filter" - var sortBy = hapi.ListSortLastReleased - var sortOrd = hapi.ListSortAsc + var sortBy = hapi.SortByLastReleased + var sortOrd = hapi.SortAsc var codes = []rls.ReleaseStatus{ rls.StatusFailed, rls.StatusDeleted, diff --git a/pkg/helm/option.go b/pkg/helm/option.go index 07f94ef8e..662e2abb6 100644 --- a/pkg/helm/option.go +++ b/pkg/helm/option.go @@ -115,14 +115,14 @@ func ReleaseListLimit(limit int) ReleaseListOption { } // ReleaseListOrder specifies how to order a list of releases. -func ReleaseListOrder(order hapi.ListSortOrder) ReleaseListOption { +func ReleaseListOrder(order hapi.SortOrder) ReleaseListOption { return func(opts *options) { opts.listReq.SortOrder = order } } // ReleaseListSort specifies how to sort a release list. -func ReleaseListSort(sort hapi.ListSortBy) ReleaseListOption { +func ReleaseListSort(sort hapi.SortBy) ReleaseListOption { return func(opts *options) { opts.listReq.SortBy = sort } diff --git a/pkg/lint/rules/chartfile.go b/pkg/lint/rules/chartfile.go index 3d7d10620..da50d0bee 100644 --- a/pkg/lint/rules/chartfile.go +++ b/pkg/lint/rules/chartfile.go @@ -117,8 +117,8 @@ func validateChartMaintainer(cf *chart.Metadata) error { return errors.New("each maintainer requires a name") } else if maintainer.Email != "" && !govalidator.IsEmail(maintainer.Email) { return fmt.Errorf("invalid email '%s' for maintainer '%s'", maintainer.Email, maintainer.Name) - } else if maintainer.Url != "" && !govalidator.IsURL(maintainer.Url) { - return fmt.Errorf("invalid url '%s' for maintainer '%s'", maintainer.Url, maintainer.Name) + } else if maintainer.URL != "" && !govalidator.IsURL(maintainer.URL) { + return fmt.Errorf("invalid url '%s' for maintainer '%s'", maintainer.URL, maintainer.Name) } } return nil diff --git a/pkg/tiller/release_list.go b/pkg/tiller/release_list.go index fc36c6365..b232935bf 100644 --- a/pkg/tiller/release_list.go +++ b/pkg/tiller/release_list.go @@ -50,13 +50,13 @@ func (s *ReleaseServer) ListReleases(req *hapi.ListReleasesRequest) ([]*release. } switch req.SortBy { - case hapi.ListSortName: + case hapi.SortByName: relutil.SortByName(rels) - case hapi.ListSortLastReleased: + case hapi.SortByLastReleased: relutil.SortByDate(rels) } - if req.SortOrder == hapi.ListSortDesc { + if req.SortOrder == hapi.SortDesc { ll := len(rels) rr := make([]*release.Release, ll) for i, item := range rels { diff --git a/pkg/tiller/release_list_test.go b/pkg/tiller/release_list_test.go index cdb474ec7..c31da8905 100644 --- a/pkg/tiller/release_list_test.go +++ b/pkg/tiller/release_list_test.go @@ -128,7 +128,7 @@ func TestListReleasesSort(t *testing.T) { req := &hapi.ListReleasesRequest{ Offset: "", Limit: int64(limit), - SortBy: hapi.ListSortName, + SortBy: hapi.SortByName, } rels, err := rs.ListReleases(req) if err != nil { @@ -171,7 +171,7 @@ func TestListReleasesFilter(t *testing.T) { Offset: "", Limit: 64, Filter: "neuro[a-z]+", - SortBy: hapi.ListSortName, + SortBy: hapi.SortByName, } rels, err := rs.ListReleases(req) if err != nil { diff --git a/pkg/urlutil/urlutil_test.go b/pkg/urlutil/urlutil_test.go index f0c82c0a9..b60c8514c 100644 --- a/pkg/urlutil/urlutil_test.go +++ b/pkg/urlutil/urlutil_test.go @@ -18,7 +18,7 @@ package urlutil import "testing" -func TestUrlJoin(t *testing.T) { +func TestURLJoin(t *testing.T) { tests := []struct { name, url, expect string paths []string diff --git a/pkg/version/version.go b/pkg/version/version.go index 6a06d5890..008740a92 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -42,6 +42,7 @@ func GetVersion() string { return version + "+" + metadata } +// BuildInfo describes the compile time information. type BuildInfo struct { // Version is the current semver. Version string `json:"version,omitempty"` @@ -52,8 +53,8 @@ type BuildInfo struct { } // GetBuildInfo returns build info -func GetBuildInfo() *BuildInfo { - return &BuildInfo{ +func GetBuildInfo() BuildInfo { + return BuildInfo{ Version: GetVersion(), GitCommit: gitCommit, GitTreeState: gitTreeState, diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index 198b03736..990db776f 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -38,9 +38,8 @@ func TestBuildInfo(t *testing.T) { metadata = tt.buildMetadata gitCommit = tt.gitCommit gitTreeState = tt.gitTreeState - if versionProto := GetBuildInfo(); *versionProto != tt.expected { - t.Errorf("expected Version(%s), GitCommit(%s) and GitTreeState(%s) to be %v", tt.expected, tt.gitCommit, tt.gitTreeState, *versionProto) + if GetBuildInfo() != tt.expected { + t.Errorf("expected Version(%s), GitCommit(%s) and GitTreeState(%s) to be %v", tt.expected, tt.gitCommit, tt.gitTreeState, GetBuildInfo()) } } - }