@@ -174,41 +174,41 @@ func (r *ContainerRunner) RunCmd(cmd *exec.Cmd) *Assertable {
174
174
// Assert runs the Assertable and
175
175
func (a Assertable ) Assert (t * testing.T , option ... Assertion ) {
176
176
slog .Helper ()
177
- var cmdResult CommandResult
178
-
179
177
var (
180
178
stdout bytes.Buffer
181
179
stderr bytes.Buffer
180
+ result CommandResult
182
181
)
183
182
184
183
a .cmd .Stdout = & stdout
185
184
a .cmd .Stderr = & stderr
186
185
187
186
start := time .Now ()
188
187
err := a .cmd .Run ()
189
- cmdResult .Duration = time .Since (start )
188
+ result .Duration = time .Since (start )
190
189
191
190
if exitErr , ok := err .(* exec.ExitError ); ok {
192
- cmdResult .ExitCode = exitErr .ExitCode ()
191
+ result .ExitCode = exitErr .ExitCode ()
193
192
} else if err != nil {
194
- cmdResult .ExitCode = - 1
193
+ // TODO: handle this case better
194
+ result .ExitCode = - 1
195
195
} else {
196
- cmdResult .ExitCode = 0
196
+ result .ExitCode = 0
197
197
}
198
198
199
- cmdResult .Stdout = stdout .Bytes ()
200
- cmdResult .Stderr = stderr .Bytes ()
199
+ result .Stdout = stdout .Bytes ()
200
+ result .Stderr = stderr .Bytes ()
201
201
202
202
slogtest .Info (t , "command output" ,
203
203
slog .F ("command" , a .cmd ),
204
- slog .F ("stdout" , string (cmdResult .Stdout )),
205
- slog .F ("stderr" , string (cmdResult .Stderr )),
206
- slog .F ("exit-code " , cmdResult .ExitCode ),
207
- slog .F ("duration" , cmdResult .Duration ),
204
+ slog .F ("stdout" , string (result .Stdout )),
205
+ slog .F ("stderr" , string (result .Stderr )),
206
+ slog .F ("exit_code " , result .ExitCode ),
207
+ slog .F ("duration" , result .Duration ),
208
208
)
209
209
210
210
for _ , assertion := range option {
211
- assertion (t , & cmdResult )
211
+ assertion (t , & result )
212
212
}
213
213
}
214
214
@@ -288,21 +288,18 @@ func StderrMatches(pattern string) Assertion {
288
288
289
289
func matches (t * testing.T , name , pattern string , target []byte ) {
290
290
slog .Helper ()
291
+ fields := []slog.Field {
292
+ slog .F ("pattern" , pattern ),
293
+ slog .F ("target" , string (target )),
294
+ slog .F ("sink" , name ),
295
+ }
291
296
292
297
ok , err := regexp .Match (pattern , target )
293
298
if err != nil {
294
- slogtest .Fatal (t , "failed to attempt regexp match" , slog .Error (err ),
295
- slog .F ("pattern" , pattern ),
296
- slog .F ("target" , string (target )),
297
- slog .F ("sink" , name ),
298
- )
299
+ slogtest .Fatal (t , "failed to attempt regexp match" , append (fields , slog .Error (err ))... )
299
300
}
300
301
if ! ok {
301
- slogtest .Fatal (t , "expected to find pattern, no match found" ,
302
- slog .F ("pattern" , pattern ),
303
- slog .F ("target" , string (target )),
304
- slog .F ("sink" , name ),
305
- )
302
+ slogtest .Fatal (t , "expected to find pattern, no match found" , fields ... )
306
303
}
307
304
}
308
305
0 commit comments