Commit 23b570fa authored by Arash Deshmeh's avatar Arash Deshmeh

fix(helm): refactor helm version command tests to remove duplication

Signed-off-by: 's avatarArash Deshmeh <adeshmeh@ca.ibm.com>
parent dede3ff1
...@@ -16,50 +16,50 @@ limitations under the License. ...@@ -16,50 +16,50 @@ limitations under the License.
package main package main
import ( import (
"bytes" "fmt"
"strings" "io"
"regexp"
"testing" "testing"
"github.com/spf13/cobra"
"k8s.io/helm/pkg/helm" "k8s.io/helm/pkg/helm"
"k8s.io/helm/pkg/version" "k8s.io/helm/pkg/version"
) )
func TestVersion(t *testing.T) { func TestVersion(t *testing.T) {
lver := regexp.QuoteMeta(version.GetVersionProto().SemVer)
sver := regexp.QuoteMeta("1.2.3-fakeclient+testonly")
clientVersion := fmt.Sprintf("Client: &version\\.Version{SemVer:\"%s\", GitCommit:\"\", GitTreeState:\"\"}\n", lver)
serverVersion := fmt.Sprintf("Server: &version\\.Version{SemVer:\"%s\", GitCommit:\"\", GitTreeState:\"\"}\n", sver)
lver := version.GetVersionProto().SemVer tests := []releaseCase{
sver := "1.2.3-fakeclient+testonly" {
name: "default",
tests := []struct { args: []string{},
name string expected: clientVersion + serverVersion,
client, server bool },
args []string {
fail bool name: "client",
}{ args: []string{},
{"default", true, true, []string{}, false}, flags: []string{"-c"},
{"client", true, false, []string{"-c"}, false}, expected: clientVersion,
{"server", false, true, []string{"-s"}, false}, },
{"template", true, true, []string{"--template='{{ .Client.SemVer }} {{ .Server.SemVer }}'"}, false}, {
name: "server",
args: []string{},
flags: []string{"-s"},
expected: serverVersion,
},
{
name: "template",
args: []string{},
flags: []string{"--template", "{{ .Client.SemVer }} {{ .Server.SemVer }}"},
expected: lver + " " + sver,
},
} }
settings.TillerHost = "fake-localhost" settings.TillerHost = "fake-localhost"
for _, tt := range tests { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
b := new(bytes.Buffer) return newVersionCmd(c, out)
c := &helm.FakeClient{} })
cmd := newVersionCmd(c, b)
cmd.ParseFlags(tt.args)
if err := cmd.RunE(cmd, tt.args); err != nil {
if tt.fail {
continue
}
t.Fatal(err)
}
if tt.client && !strings.Contains(b.String(), lver) {
t.Errorf("Expected %q to contain %q", b.String(), lver)
}
if tt.server && !strings.Contains(b.String(), sver) {
t.Errorf("Expected %q to contain %q", b.String(), sver)
}
}
} }
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