Skip to content

Commit e7b192a

Browse files
committed
Simplify helm_test
1 parent 389905f commit e7b192a

File tree

1 file changed

+20
-29
lines changed

1 file changed

+20
-29
lines changed

pkg/skaffold/deploy/helm_test.go

+20-29
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func TestHelmDeploy(t *testing.T) {
9696
description: "get failure should install not upgrade",
9797
cmd: &MockHelm{
9898
t: t,
99-
getResult: cmdOutput{"", fmt.Errorf("not found")},
100-
upgradeResult: cmdOutput{"", fmt.Errorf("should not have called upgrade")},
99+
getResult: fmt.Errorf("not found"),
100+
upgradeResult: fmt.Errorf("should not have called upgrade"),
101101
},
102102
deployer: NewHelmDeployer(testDeployConfig, testKubeContext),
103103
builds: testBuilds,
@@ -106,7 +106,7 @@ func TestHelmDeploy(t *testing.T) {
106106
description: "get success should upgrade not install",
107107
cmd: &MockHelm{
108108
t: t,
109-
installResult: cmdOutput{"", fmt.Errorf("should not have called install")},
109+
installResult: fmt.Errorf("should not have called install"),
110110
},
111111
deployer: NewHelmDeployer(testDeployConfig, testKubeContext),
112112
builds: testBuilds,
@@ -115,7 +115,7 @@ func TestHelmDeploy(t *testing.T) {
115115
description: "deploy error",
116116
cmd: &MockHelm{
117117
t: t,
118-
upgradeResult: cmdOutput{"", fmt.Errorf("unexpected error")},
118+
upgradeResult: fmt.Errorf("unexpected error"),
119119
},
120120
shouldErr: true,
121121
deployer: NewHelmDeployer(testDeployConfig, testKubeContext),
@@ -125,7 +125,7 @@ func TestHelmDeploy(t *testing.T) {
125125
description: "dep build error",
126126
cmd: &MockHelm{
127127
t: t,
128-
depResult: cmdOutput{"", fmt.Errorf("unexpected error")},
128+
depResult: fmt.Errorf("unexpected error"),
129129
},
130130
shouldErr: true,
131131
deployer: NewHelmDeployer(testDeployConfig, testKubeContext),
@@ -145,24 +145,20 @@ func TestHelmDeploy(t *testing.T) {
145145
}
146146

147147
type MockHelm struct {
148-
getResult cmdOutput
149-
installResult cmdOutput
150-
upgradeResult cmdOutput
151-
depResult cmdOutput
152-
153148
t *testing.T
154-
}
155149

156-
type cmdOutput struct {
157-
stdout string
158-
err error
150+
getResult error
151+
installResult error
152+
upgradeResult error
153+
depResult error
159154
}
160155

161-
func (c cmdOutput) out() ([]byte, error) {
162-
return []byte(c.stdout), c.err
156+
func (m *MockHelm) RunCmdOut(c *exec.Cmd) ([]byte, error) {
157+
m.t.Error("Shouldn't be used")
158+
return nil, nil
163159
}
164160

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

174170
switch c.Args[3] {
175171
case "get":
176-
return m.getResult.out()
172+
return m.getResult
177173
case "install":
178-
return m.installResult.out()
174+
return m.installResult
179175
case "upgrade":
180-
return m.upgradeResult.out()
176+
return m.upgradeResult
181177
case "dep":
182-
return m.depResult.out()
178+
return m.depResult
179+
default:
180+
m.t.Errorf("Unknown helm command: %+v", c)
181+
return nil
183182
}
184-
185-
m.t.Errorf("Unknown helm command: %+v", c)
186-
return nil, nil
187-
}
188-
189-
func (m *MockHelm) RunCmd(c *exec.Cmd) error {
190-
_, err := m.RunCmdOut(c)
191-
return err
192183
}

0 commit comments

Comments
 (0)