From 260a017a1779a79ee67a24b3f1781dc0e3279bd9 Mon Sep 17 00:00:00 2001 From: Mustafa Abdelrahman Date: Wed, 20 Nov 2024 15:39:16 +0100 Subject: [PATCH] multiflag: add simple testcases Signed-off-by: Mustafa Abdelrahman --- config/config_test.go | 9 --------- config/multiflag_test.go | 41 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 config/multiflag_test.go diff --git a/config/config_test.go b/config/config_test.go index bad7f480ec..49da49cd04 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -14,7 +14,6 @@ import ( "github.com/zalando/skipper/filters/openpolicyagent" "github.com/zalando/skipper/net" "github.com/zalando/skipper/proxy" - "gopkg.in/yaml.v2" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -482,11 +481,3 @@ func TestDeprecatedFlags(t *testing.T) { } } } - -func TestMultiFlagYamlErr(t *testing.T) { - m := &multiFlag{} - err := yaml.Unmarshal([]byte(`foo=bar`), m) - if err == nil { - t.Error("Failed to get error on wrong yaml input") - } -} diff --git a/config/multiflag_test.go b/config/multiflag_test.go new file mode 100644 index 0000000000..eb1e6c599a --- /dev/null +++ b/config/multiflag_test.go @@ -0,0 +1,41 @@ +package config + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "gopkg.in/yaml.v2" +) + +func TestMultiFlagSet(t *testing.T) { + for _, tc := range []struct { + name string + args string + values string + }{ + { + name: "single value", + args: "foo=bar", + values: "foo=bar", + }, + { + name: "multiple values", + args: "foo=bar foo=baz foo=qux bar=baz", + values: "foo=bar foo=baz foo=qux bar=baz", + }, + } { + t.Run(tc.name+"_valid", func(t *testing.T) { + multiFlag := &multiFlag{} + err := multiFlag.Set(tc.args) + require.NoError(t, err) + assert.Equal(t, tc.values, multiFlag.String()) + }) + } +} + +func TestMultiFlagYamlErr(t *testing.T) { + m := &multiFlag{} + err := yaml.Unmarshal([]byte(`-foo=bar`), m) + require.Error(t, err, "Failed to get error on wrong yaml input") +}