Skip to content

Commit

Permalink
Merge pull request #607 from dgageot/simplify-help-test
Browse files Browse the repository at this point in the history
Simplify helm_test
  • Loading branch information
dgageot authored May 31, 2018
2 parents cd5f065 + e7b192a commit 50d6c39
Showing 1 changed file with 20 additions and 29 deletions.
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
}

0 comments on commit 50d6c39

Please sign in to comment.