...
1
16
17 package metrics
18
19 import "testing"
20
21 func TestValidateAllowMetricLabel(t *testing.T) {
22 var tests = []struct {
23 name string
24 input map[string]string
25 expectedError bool
26 }{
27 {
28 "validated",
29 map[string]string{
30 "metric_name,label_name": "labelValue1,labelValue2",
31 },
32 false,
33 },
34 {
35 "metric name is not valid",
36 map[string]string{
37 "-metric_name,label_name": "labelValue1,labelValue2",
38 },
39 true,
40 },
41 {
42 "label name is not valid",
43 map[string]string{
44 "metric_name,:label_name": "labelValue1,labelValue2",
45 },
46 true,
47 },
48 {
49 "no label name",
50 map[string]string{
51 "metric_name": "labelValue1,labelValue2",
52 },
53 true,
54 },
55 }
56 for _, tt := range tests {
57 t.Run(tt.name, func(t *testing.T) {
58 err := validateAllowMetricLabel(tt.input)
59 if err == nil && tt.expectedError {
60 t.Error("Got error is nil, wanted error is not nil")
61 }
62 if err != nil && !tt.expectedError {
63 t.Errorf("Got error is %v, wanted no error", err)
64 }
65 })
66 }
67 }
68
View as plain text