mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-30 18:17:55 +00:00
Added a small utility method to display warnings when parsing command arguments. (#16441)
* Added a small utility method to display warnings when parsing command arguments Will print warning if flag is passed after arguments e.g. vault <command> -a b -c In this example -c will be interpreted as an argument which may be misleading
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -209,3 +210,48 @@ func TestParseFlagFile(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgWarnings(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
cases := []struct {
|
||||
args []string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
[]string{"a", "b", "c"},
|
||||
"",
|
||||
},
|
||||
{
|
||||
[]string{"a", "-b"},
|
||||
"-b",
|
||||
},
|
||||
{
|
||||
[]string{"a", "--b"},
|
||||
"--b",
|
||||
},
|
||||
{
|
||||
[]string{"a-b", "-c"},
|
||||
"-c",
|
||||
},
|
||||
{
|
||||
[]string{"a", "-b-c"},
|
||||
"-b-c",
|
||||
},
|
||||
{
|
||||
[]string{"-a", "b"},
|
||||
"-a",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
tc := tc
|
||||
|
||||
t.Run(tc.expected, func(t *testing.T) {
|
||||
warnings := generateFlagWarnings(tc.args)
|
||||
if !strings.Contains(warnings, tc.expected) {
|
||||
t.Fatalf("expected %s to contain %s", warnings, tc.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user