...
1 package capability
2
3 import "testing"
4
5 func TestCapabilities_Set(t *testing.T) {
6 tcs := map[string]struct {
7 value string
8 result string
9 }{
10 "one": {"prometheus", "prometheus"},
11 "two": {"prometheus,linkerd", "linkerd,prometheus"},
12 "trailing comma": {"prometheus,linkerd,", "linkerd,prometheus"},
13 "leading comma": {",prometheus,linkerd", "linkerd,prometheus"},
14 "dupes": {"prometheus,prometheus,linkerd", "linkerd,prometheus"},
15 "blank": {"", ""},
16 "comma": {",", ""},
17 }
18
19 for name, tc := range tcs {
20 t.Run(name, func(t *testing.T) {
21 var c Capabilities
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 Capabilities
32 _ = c.Set("linkerd")
33 _ = c.Set("prometheus")
34
35 expected := "linkerd,prometheus"
36
37 if c.String() != expected {
38 t.Errorf("expected %s, got %s", expected, c.String())
39 }
40 })
41 }
42
View as plain text