Skip to content

Commit c088797

Browse files
committed
multiflag: add simple testcases
Signed-off-by: Mustafa Abdelrahman <[email protected]>
1 parent f6f9efb commit c088797

File tree

2 files changed

+56
-9
lines changed

2 files changed

+56
-9
lines changed

config/config_test.go

-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/zalando/skipper/filters/openpolicyagent"
1515
"github.com/zalando/skipper/net"
1616
"github.com/zalando/skipper/proxy"
17-
"gopkg.in/yaml.v2"
1817

1918
"github.com/google/go-cmp/cmp"
2019
"github.com/google/go-cmp/cmp/cmpopts"
@@ -482,11 +481,3 @@ func TestDeprecatedFlags(t *testing.T) {
482481
}
483482
}
484483
}
485-
486-
func TestMultiFlagYamlErr(t *testing.T) {
487-
m := &multiFlag{}
488-
err := yaml.Unmarshal([]byte(`foo=bar`), m)
489-
if err == nil {
490-
t.Error("Failed to get error on wrong yaml input")
491-
}
492-
}

config/multiflag_test.go

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package config
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
"github.com/stretchr/testify/require"
8+
"gopkg.in/yaml.v2"
9+
)
10+
11+
func TestMultiFlagSet(t *testing.T) {
12+
for _, tc := range []struct {
13+
name string
14+
args string
15+
values string
16+
wantErr bool
17+
}{
18+
{
19+
name: "single value",
20+
args: "foo=bar",
21+
values: "foo=bar",
22+
wantErr: false,
23+
},
24+
{
25+
name: "multiple values",
26+
args: "foo=bar foo=baz foo=qux bar=baz",
27+
values: "foo=bar foo=baz foo=qux bar=baz",
28+
wantErr: false,
29+
},
30+
} {
31+
t.Run(tc.name, func(t *testing.T) {
32+
multiFlag := &multiFlag{}
33+
err := multiFlag.Set(tc.args)
34+
require.Condition(t, func() bool {
35+
if (err != nil) && tc.wantErr == false {
36+
t.Logf("set error: %v", err)
37+
return false
38+
} else if (err == nil) && tc.wantErr == true {
39+
t.Logf("expected error, got nil")
40+
return false
41+
} else if err != nil {
42+
return false
43+
}
44+
return true
45+
}, "error: %v, wantErr: %v", err, tc.wantErr)
46+
47+
assert.Equal(t, tc.values, multiFlag.String())
48+
})
49+
}
50+
}
51+
52+
func TestMultiFlagYamlErr(t *testing.T) {
53+
m := &multiFlag{}
54+
err := yaml.Unmarshal([]byte(`-foo=bar`), m)
55+
require.Error(t, err, "Failed to get error on wrong yaml input")
56+
}

0 commit comments

Comments
 (0)