fix (cli): return error msg if acl policy not found (#16485)
* fix: return error msg if acl policy not found * changelog * add test
This commit is contained in:
parent
e4241fa47d
commit
452ec19a42
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
cli: fix panic read non-existent acl policy
|
||||
```
|
|
@ -92,6 +92,11 @@ func (c *cmd) Run(args []string) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
if pol == nil {
|
||||
c.UI.Error(fmt.Sprintf("Error policy not found: %s", c.policyName))
|
||||
return 1
|
||||
}
|
||||
|
||||
formatter, err := policy.NewFormatter(c.format, c.showMeta)
|
||||
if err != nil {
|
||||
c.UI.Error(err.Error())
|
||||
|
|
|
@ -82,6 +82,17 @@ func TestPolicyReadCommand(t *testing.T) {
|
|||
output = ui.OutputWriter.String()
|
||||
assert.Contains(t, output, fmt.Sprintf("test-policy"))
|
||||
assert.Contains(t, output, policy.ID)
|
||||
|
||||
// Test querying non-existent policy
|
||||
argsName = []string{
|
||||
"-http-addr=" + a.HTTPAddr(),
|
||||
"-token=root",
|
||||
"-name=test-policy-not-exist",
|
||||
}
|
||||
|
||||
cmd = New(ui)
|
||||
code = cmd.Run(argsName)
|
||||
assert.Equal(t, code, 1)
|
||||
}
|
||||
|
||||
func TestPolicyReadCommand_JSON(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue