Add backwards-compatibility for flags passed to plugins (#2479)

* update plugin server to ignore unknown flags during parse

Signed-off-by: Steve Kriss <krisss@vmware.com>
This commit is contained in:
Steve Kriss
2020-04-30 13:19:55 -07:00
committed by GitHub
parent dc3593ab15
commit e148ddad8f
4 changed files with 107 additions and 1 deletions
+50
View File
@@ -121,3 +121,53 @@ func TestDispense(t *testing.T) {
})
}
}
func Test_removeFeaturesFlag(t *testing.T) {
tests := []struct {
name string
commandArgs []string
want []string
}{
{
name: "when commandArgs is nil, a nil slice is returned",
commandArgs: nil,
want: nil,
},
{
name: "when commandArgs is empty, a nil slice is returned",
commandArgs: []string{},
want: nil,
},
{
name: "when commandArgs does not contain --features, it is returned as-is",
commandArgs: []string{"--log-level", "debug", "--another-flag", "foo"},
want: []string{"--log-level", "debug", "--another-flag", "foo"},
},
{
name: "when --features is the only flag, a nil slice is returned",
commandArgs: []string{"--features", "EnableCSI"},
want: nil,
},
{
name: "when --features is the first flag, it's properly removed",
commandArgs: []string{"--features", "EnableCSI", "--log-level", "debug", "--another-flag", "foo"},
want: []string{"--log-level", "debug", "--another-flag", "foo"},
},
{
name: "when --features is the last flag, it's properly removed",
commandArgs: []string{"--log-level", "debug", "--another-flag", "foo", "--features", "EnableCSI"},
want: []string{"--log-level", "debug", "--another-flag", "foo"},
},
{
name: "when --features is neither the first nor last flag, it's properly removed",
commandArgs: []string{"--log-level", "debug", "--features", "EnableCSI", "--another-flag", "foo"},
want: []string{"--log-level", "debug", "--another-flag", "foo"},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.want, removeFeaturesFlag(tc.commandArgs))
})
}
}