@@ -157,7 +157,7 @@ func (a Assertable) Assert(t *testing.T, option ...Assertion) {
157
157
}
158
158
t .Run (name , func (t * testing.T ) {
159
159
t .Parallel ()
160
- err := o .Valid (cmdResult )
160
+ err := o .Valid (& cmdResult )
161
161
assert .Success (t , name , err )
162
162
})
163
163
}
@@ -167,7 +167,7 @@ func (a Assertable) Assert(t *testing.T, option ...Assertion) {
167
167
// Assertion specifies an assertion on the given CommandResult.
168
168
// Pass custom Assertion types to cover special cases.
169
169
type Assertion interface {
170
- Valid (r CommandResult ) error
170
+ Valid (r * CommandResult ) error
171
171
}
172
172
173
173
// Named is an optional extension of Assertion that provides a helpful label
@@ -184,11 +184,11 @@ type CommandResult struct {
184
184
}
185
185
186
186
type simpleFuncAssert struct {
187
- valid func (r CommandResult ) error
187
+ valid func (r * CommandResult ) error
188
188
name string
189
189
}
190
190
191
- func (s simpleFuncAssert ) Valid (r CommandResult ) error {
191
+ func (s simpleFuncAssert ) Valid (r * CommandResult ) error {
192
192
return s .valid (r )
193
193
}
194
194
@@ -204,7 +204,7 @@ func Success() Assertion {
204
204
// ExitCodeIs asserts that the command exited with the given code
205
205
func ExitCodeIs (code int ) Assertion {
206
206
return simpleFuncAssert {
207
- valid : func (r CommandResult ) error {
207
+ valid : func (r * CommandResult ) error {
208
208
if r .ExitCode != code {
209
209
return xerrors .Errorf ("exit code of %v expected, got %v" , code , r .ExitCode )
210
210
}
@@ -217,17 +217,29 @@ func ExitCodeIs(code int) Assertion {
217
217
// StdoutEmpty asserts that the command did not write any data to Stdout
218
218
func StdoutEmpty () Assertion {
219
219
return simpleFuncAssert {
220
- valid : func (r CommandResult ) error {
220
+ valid : func (r * CommandResult ) error {
221
221
return empty ("stdout" , r .Stdout )
222
222
},
223
223
name : fmt .Sprintf ("stdout-empty" ),
224
224
}
225
225
}
226
226
227
+ // GetResult offers an escape hatch from tcli
228
+ // The passed pointer will be assigned to the commands *CommandResult
229
+ func GetResult (result * * CommandResult ) Assertion {
230
+ return simpleFuncAssert {
231
+ valid : func (r * CommandResult ) error {
232
+ * result = r
233
+ return nil
234
+ },
235
+ name : "get-stdout" ,
236
+ }
237
+ }
238
+
227
239
// StderrEmpty asserts that the command did not write any data to Stderr
228
240
func StderrEmpty () Assertion {
229
241
return simpleFuncAssert {
230
- valid : func (r CommandResult ) error {
242
+ valid : func (r * CommandResult ) error {
231
243
return empty ("stderr" , r .Stderr )
232
244
},
233
245
name : fmt .Sprintf ("stderr-empty" ),
@@ -237,7 +249,7 @@ func StderrEmpty() Assertion {
237
249
// StdoutMatches asserts that Stdout contains a substring which matches the given regexp
238
250
func StdoutMatches (pattern string ) Assertion {
239
251
return simpleFuncAssert {
240
- valid : func (r CommandResult ) error {
252
+ valid : func (r * CommandResult ) error {
241
253
return matches ("stdout" , pattern , r .Stdout )
242
254
},
243
255
name : fmt .Sprintf ("stdout-matches" ),
@@ -247,7 +259,7 @@ func StdoutMatches(pattern string) Assertion {
247
259
// StderrMatches asserts that Stderr contains a substring which matches the given regexp
248
260
func StderrMatches (pattern string ) Assertion {
249
261
return simpleFuncAssert {
250
- valid : func (r CommandResult ) error {
262
+ valid : func (r * CommandResult ) error {
251
263
return matches ("stderr" , pattern , r .Stderr )
252
264
},
253
265
name : fmt .Sprintf ("stderr-matches" ),
@@ -257,7 +269,7 @@ func StderrMatches(pattern string) Assertion {
257
269
// CombinedMatches asserts that either Stdout or Stderr a substring which matches the given regexp
258
270
func CombinedMatches (pattern string ) Assertion {
259
271
return simpleFuncAssert {
260
- valid : func (r CommandResult ) error {
272
+ valid : func (r * CommandResult ) error {
261
273
//stdoutValid := StdoutMatches(pattern).Valid(r)
262
274
//stderrValid := StderrMatches(pattern).Valid(r)
263
275
// TODO: combine errors
@@ -291,7 +303,7 @@ func empty(name string, a []byte) error {
291
303
// DurationLessThan asserts that the command completed in less than the given duration
292
304
func DurationLessThan (dur time.Duration ) Assertion {
293
305
return simpleFuncAssert {
294
- valid : func (r CommandResult ) error {
306
+ valid : func (r * CommandResult ) error {
295
307
if r .Duration > dur {
296
308
return xerrors .Errorf ("expected duration less than %s, took %s" , dur .String (), r .Duration .String ())
297
309
}
@@ -304,7 +316,7 @@ func DurationLessThan(dur time.Duration) Assertion {
304
316
// DurationGreaterThan asserts that the command completed in greater than the given duration
305
317
func DurationGreaterThan (dur time.Duration ) Assertion {
306
318
return simpleFuncAssert {
307
- valid : func (r CommandResult ) error {
319
+ valid : func (r * CommandResult ) error {
308
320
if r .Duration < dur {
309
321
return xerrors .Errorf ("expected duration greater than %s, took %s" , dur .String (), r .Duration .String ())
310
322
}
0 commit comments