mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 10:15:22 +00:00
fix:kustomize cfg grep with no arguments causes panic (#5707)
* fix:kustomize cfg grep with no arguments causes panic * add test for kustomize cfg grep with no arguments
This commit is contained in:
@@ -54,6 +54,9 @@ type GrepRunner struct {
|
||||
}
|
||||
|
||||
func (r *GrepRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("missing required argument: QUERY")
|
||||
}
|
||||
r.GrepFilter.Compare = func(a, b string) (int, error) {
|
||||
qa, err := resource.ParseQuantity(a)
|
||||
if err != nil {
|
||||
|
||||
@@ -421,3 +421,17 @@ spec:
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestGrepCmd_noQuery verifies the grep command errors when QUERY argument is missing
|
||||
func TestGrepCmd_noQuery(t *testing.T) {
|
||||
b := &bytes.Buffer{}
|
||||
r := commands.GetGrepRunner("")
|
||||
// No QUERY argument
|
||||
r.Command.SetArgs([]string{})
|
||||
r.Command.SetOut(b)
|
||||
|
||||
err := r.Command.Execute()
|
||||
if assert.Error(t, err) {
|
||||
assert.Contains(t, err.Error(), "missing required argument: QUERY")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user