Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify helm_test #607

Merged
merged 1 commit into from
May 31, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 20 additions & 29 deletions pkg/skaffold/deploy/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func TestHelmDeploy(t *testing.T) {
description: "get failure should install not upgrade",
cmd: &MockHelm{
t: t,
getResult: cmdOutput{"", fmt.Errorf("not found")},
upgradeResult: cmdOutput{"", fmt.Errorf("should not have called upgrade")},
getResult: fmt.Errorf("not found"),
upgradeResult: fmt.Errorf("should not have called upgrade"),
},
deployer: NewHelmDeployer(testDeployConfig, testKubeContext),
builds: testBuilds,
Expand All @@ -106,7 +106,7 @@ func TestHelmDeploy(t *testing.T) {
description: "get success should upgrade not install",
cmd: &MockHelm{
t: t,
installResult: cmdOutput{"", fmt.Errorf("should not have called install")},
installResult: fmt.Errorf("should not have called install"),
},
deployer: NewHelmDeployer(testDeployConfig, testKubeContext),
builds: testBuilds,
Expand All @@ -115,7 +115,7 @@ func TestHelmDeploy(t *testing.T) {
description: "deploy error",
cmd: &MockHelm{
t: t,
upgradeResult: cmdOutput{"", fmt.Errorf("unexpected error")},
upgradeResult: fmt.Errorf("unexpected error"),
},
shouldErr: true,
deployer: NewHelmDeployer(testDeployConfig, testKubeContext),
Expand All @@ -125,7 +125,7 @@ func TestHelmDeploy(t *testing.T) {
description: "dep build error",
cmd: &MockHelm{
t: t,
depResult: cmdOutput{"", fmt.Errorf("unexpected error")},
depResult: fmt.Errorf("unexpected error"),
},
shouldErr: true,
deployer: NewHelmDeployer(testDeployConfig, testKubeContext),
Expand All @@ -145,24 +145,20 @@ func TestHelmDeploy(t *testing.T) {
}

type MockHelm struct {
getResult cmdOutput
installResult cmdOutput
upgradeResult cmdOutput
depResult cmdOutput

t *testing.T
}

type cmdOutput struct {
stdout string
err error
getResult error
installResult error
upgradeResult error
depResult error
}

func (c cmdOutput) out() ([]byte, error) {
return []byte(c.stdout), c.err
func (m *MockHelm) RunCmdOut(c *exec.Cmd) ([]byte, error) {
m.t.Error("Shouldn't be used")
return nil, nil
}

func (m *MockHelm) RunCmdOut(c *exec.Cmd) ([]byte, error) {
func (m *MockHelm) RunCmd(c *exec.Cmd) error {
if len(c.Args) < 3 {
m.t.Errorf("Not enough args in command %v", c)
}
Expand All @@ -173,20 +169,15 @@ func (m *MockHelm) RunCmdOut(c *exec.Cmd) ([]byte, error) {

switch c.Args[3] {
case "get":
return m.getResult.out()
return m.getResult
case "install":
return m.installResult.out()
return m.installResult
case "upgrade":
return m.upgradeResult.out()
return m.upgradeResult
case "dep":
return m.depResult.out()
return m.depResult
default:
m.t.Errorf("Unknown helm command: %+v", c)
return nil
}

m.t.Errorf("Unknown helm command: %+v", c)
return nil, nil
}

func (m *MockHelm) RunCmd(c *exec.Cmd) error {
_, err := m.RunCmdOut(c)
return err
}