Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiflag: add simple testcases #3314

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
}
41 changes: 41 additions & 0 deletions config/multiflag_test.go
Original file line number Diff line number Diff line change
@@ -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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add another test for invalid and yaml

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")
}
Loading