...
1 package bazel
2
3 import "testing"
4
5 func TestConfigs_Set(t *testing.T) {
6 tcs := map[string]struct {
7 value string
8 result string
9 }{
10 "one": {"containers", "containers"},
11 "two": {"containers,ci", "containers,ci"},
12 "trailing comma": {"containers,ci,", "containers,ci"},
13 "leading comma": {",containers,ci", "containers,ci"},
14 "dupes": {"containers,containers,ci", "containers,ci"},
15 "blank": {"", ""},
16 "comma": {",", ""},
17 }
18
19 for name, tc := range tcs {
20 t.Run(name, func(t *testing.T) {
21 var c Configs
22 _ = c.Set(tc.value)
23
24 if c.String() != tc.result {
25 t.Errorf("expected %s, got %s", tc.result, c.String())
26 }
27 })
28 }
29
30 t.Run("accumulates", func(t *testing.T) {
31 var c Configs
32 _ = c.Set("containers")
33 _ = c.Set("ci")
34
35 expected := "containers,ci"
36
37 if c.String() != expected {
38 t.Errorf("expected %s, got %s", expected, c.String())
39 }
40 })
41 }
42
View as plain text