File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
cmd/config/internal/commands Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,9 @@ type GrepRunner struct {
54
54
}
55
55
56
56
func (r * GrepRunner ) preRunE (c * cobra.Command , args []string ) error {
57
+ if len (args ) == 0 {
58
+ return fmt .Errorf ("missing required argument: QUERY" )
59
+ }
57
60
r .GrepFilter .Compare = func (a , b string ) (int , error ) {
58
61
qa , err := resource .ParseQuantity (a )
59
62
if err != nil {
Original file line number Diff line number Diff line change @@ -421,3 +421,17 @@ spec:
421
421
})
422
422
}
423
423
}
424
+
425
+ // TestGrepCmd_noQuery verifies the grep command errors when QUERY argument is missing
426
+ func TestGrepCmd_noQuery (t * testing.T ) {
427
+ b := & bytes.Buffer {}
428
+ r := commands .GetGrepRunner ("" )
429
+ // No QUERY argument
430
+ r .Command .SetArgs ([]string {})
431
+ r .Command .SetOut (b )
432
+
433
+ err := r .Command .Execute ()
434
+ if assert .Error (t , err ) {
435
+ assert .Contains (t , err .Error (), "missing required argument: QUERY" )
436
+ }
437
+ }
You can’t perform that action at this time.
0 commit comments