package capability import "testing" func TestCapabilities_Set(t *testing.T) { tcs := map[string]struct { value string result string }{ "one": {"prometheus", "prometheus"}, "two": {"prometheus,linkerd", "linkerd,prometheus"}, "trailing comma": {"prometheus,linkerd,", "linkerd,prometheus"}, "leading comma": {",prometheus,linkerd", "linkerd,prometheus"}, "dupes": {"prometheus,prometheus,linkerd", "linkerd,prometheus"}, "blank": {"", ""}, "comma": {",", ""}, } for name, tc := range tcs { t.Run(name, func(t *testing.T) { var c Capabilities _ = c.Set(tc.value) if c.String() != tc.result { t.Errorf("expected %s, got %s", tc.result, c.String()) } }) } t.Run("accumulates", func(t *testing.T) { var c Capabilities _ = c.Set("linkerd") _ = c.Set("prometheus") expected := "linkerd,prometheus" if c.String() != expected { t.Errorf("expected %s, got %s", expected, c.String()) } }) }