test for blank args for TF_CLI_ARGS

This commit is contained in:
Mitchell Hashimoto 2017-02-13 14:53:50 -08:00
parent f7e535ed6e
commit 53796fcdb0
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 17 additions and 1 deletions

View File

@ -153,7 +153,7 @@ func wrappedMain() int {
// after the first non-flag arg.
idx := -1
for i, v := range args {
if v[0] != '-' {
if len(v) > 0 && v[0] != '-' {
idx = i
break
}

View File

@ -56,6 +56,22 @@ func TestMain_cliArgsFromEnv(t *testing.T) {
false,
},
{
"cli string has blank values",
[]string{testCommandName, "bar", "", "baz"},
"-foo bar",
[]string{"-foo", "bar", "bar", "", "baz"},
false,
},
{
"cli string has blank values before the command",
[]string{"", testCommandName, "bar"},
"-foo bar",
[]string{"-foo", "bar", "bar"},
false,
},
{
// this should fail gracefully, this is just testing
// that we don't panic with our slice arithmetic