@@ -96,8 +96,8 @@ func TestHelmDeploy(t *testing.T) {
96
96
description : "get failure should install not upgrade" ,
97
97
cmd : & MockHelm {
98
98
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" ),
101
101
},
102
102
deployer : NewHelmDeployer (testDeployConfig , testKubeContext ),
103
103
builds : testBuilds ,
@@ -106,7 +106,7 @@ func TestHelmDeploy(t *testing.T) {
106
106
description : "get success should upgrade not install" ,
107
107
cmd : & MockHelm {
108
108
t : t ,
109
- installResult : cmdOutput { "" , fmt .Errorf ("should not have called install" )} ,
109
+ installResult : fmt .Errorf ("should not have called install" ),
110
110
},
111
111
deployer : NewHelmDeployer (testDeployConfig , testKubeContext ),
112
112
builds : testBuilds ,
@@ -115,7 +115,7 @@ func TestHelmDeploy(t *testing.T) {
115
115
description : "deploy error" ,
116
116
cmd : & MockHelm {
117
117
t : t ,
118
- upgradeResult : cmdOutput { "" , fmt .Errorf ("unexpected error" )} ,
118
+ upgradeResult : fmt .Errorf ("unexpected error" ),
119
119
},
120
120
shouldErr : true ,
121
121
deployer : NewHelmDeployer (testDeployConfig , testKubeContext ),
@@ -125,7 +125,7 @@ func TestHelmDeploy(t *testing.T) {
125
125
description : "dep build error" ,
126
126
cmd : & MockHelm {
127
127
t : t ,
128
- depResult : cmdOutput { "" , fmt .Errorf ("unexpected error" )} ,
128
+ depResult : fmt .Errorf ("unexpected error" ),
129
129
},
130
130
shouldErr : true ,
131
131
deployer : NewHelmDeployer (testDeployConfig , testKubeContext ),
@@ -145,24 +145,20 @@ func TestHelmDeploy(t *testing.T) {
145
145
}
146
146
147
147
type MockHelm struct {
148
- getResult cmdOutput
149
- installResult cmdOutput
150
- upgradeResult cmdOutput
151
- depResult cmdOutput
152
-
153
148
t * testing.T
154
- }
155
149
156
- type cmdOutput struct {
157
- stdout string
158
- err error
150
+ getResult error
151
+ installResult error
152
+ upgradeResult error
153
+ depResult error
159
154
}
160
155
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
163
159
}
164
160
165
- func (m * MockHelm ) RunCmdOut (c * exec.Cmd ) ([] byte , error ) {
161
+ func (m * MockHelm ) RunCmd (c * exec.Cmd ) error {
166
162
if len (c .Args ) < 3 {
167
163
m .t .Errorf ("Not enough args in command %v" , c )
168
164
}
@@ -173,20 +169,15 @@ func (m *MockHelm) RunCmdOut(c *exec.Cmd) ([]byte, error) {
173
169
174
170
switch c .Args [3 ] {
175
171
case "get" :
176
- return m .getResult . out ()
172
+ return m .getResult
177
173
case "install" :
178
- return m .installResult . out ()
174
+ return m .installResult
179
175
case "upgrade" :
180
- return m .upgradeResult . out ()
176
+ return m .upgradeResult
181
177
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
183
182
}
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
192
183
}
0 commit comments