Unverified Commit 8d5f215e authored by Matthew Fisher's avatar Matthew Fisher Committed by GitHub

Merge pull request #3705 from adshmh/fix-duplication-of-test-code-on-helm-dependency

Refactor tests on helm dependency list command to remove duplication
parents c4c165e8 74bf7584
...@@ -16,19 +16,17 @@ limitations under the License. ...@@ -16,19 +16,17 @@ limitations under the License.
package main package main
import ( import (
"bytes" "io"
"strings"
"testing" "testing"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/helm"
) )
func TestDependencyListCmd(t *testing.T) { func TestDependencyListCmd(t *testing.T) {
tests := []struct { tests := []releaseCase{
name string
args []string
expect string
err bool
}{
{ {
name: "No such chart", name: "No such chart",
args: []string{"/no/such/chart"}, args: []string{"/no/such/chart"},
...@@ -37,12 +35,12 @@ func TestDependencyListCmd(t *testing.T) { ...@@ -37,12 +35,12 @@ func TestDependencyListCmd(t *testing.T) {
{ {
name: "No requirements.yaml", name: "No requirements.yaml",
args: []string{"testdata/testcharts/alpine"}, args: []string{"testdata/testcharts/alpine"},
expect: "WARNING: no requirements at ", expected: "WARNING: no requirements at ",
}, },
{ {
name: "Requirements in chart dir", name: "Requirements in chart dir",
args: []string{"testdata/testcharts/reqtest"}, args: []string{"testdata/testcharts/reqtest"},
expect: "NAME \tVERSION\tREPOSITORY \tSTATUS \n" + expected: "NAME \tVERSION\tREPOSITORY \tSTATUS \n" +
"reqsubchart \t0.1.0 \thttps://example.com/charts\tunpacked\n" + "reqsubchart \t0.1.0 \thttps://example.com/charts\tunpacked\n" +
"reqsubchart2\t0.2.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", "reqsubchart3\t>=0.1.0\thttps://example.com/charts\tok \n\n",
...@@ -50,25 +48,11 @@ func TestDependencyListCmd(t *testing.T) { ...@@ -50,25 +48,11 @@ func TestDependencyListCmd(t *testing.T) {
{ {
name: "Requirements in chart archive", name: "Requirements in chart archive",
args: []string{"testdata/testcharts/reqtest-0.1.0.tgz"}, args: []string{"testdata/testcharts/reqtest-0.1.0.tgz"},
expect: "NAME \tVERSION\tREPOSITORY \tSTATUS \nreqsubchart \t0.1.0 \thttps://example.com/charts\tmissing\nreqsubchart2\t0.2.0 \thttps://example.com/charts\tmissing\n", expected: "NAME \tVERSION\tREPOSITORY \tSTATUS \nreqsubchart \t0.1.0 \thttps://example.com/charts\tmissing\nreqsubchart2\t0.2.0 \thttps://example.com/charts\tmissing\n",
}, },
} }
for _, tt := range tests { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
buf := bytes.NewBuffer(nil) return newDependencyListCmd(out)
dlc := newDependencyListCmd(buf) })
if err := dlc.RunE(dlc, tt.args); err != nil {
if tt.err {
continue
}
t.Errorf("Test %q: %s", tt.name, err)
continue
}
got := buf.String()
if !strings.Contains(got, tt.expect) {
t.Errorf("Test: %q, Expected:\n%q\nGot:\n%q", tt.name, tt.expect, got)
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment