MCPcopy
hub / github.com/grafana/k6 / TestAddSubmetric

Function TestAddSubmetric

metrics/metric_test.go:33–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

31}
32
33func TestAddSubmetric(t *testing.T) {
34 t.Parallel()
35 testdata := map[string]struct {
36 err bool
37 tags map[string]string
38 }{
39 "": {true, nil},
40 " ": {true, nil},
41 "a": {false, map[string]string{"a": ""}},
42 "a:1": {false, map[string]string{"a": "1"}},
43 " a : 1 ": {false, map[string]string{"a": "1"}},
44 "a,b": {false, map[string]string{"a": "", "b": ""}},
45 ` a:"",b: ''`: {false, map[string]string{"a": "", "b": ""}},
46 `a:1,b:2`: {false, map[string]string{"a": "1", "b": "2"}},
47 ` a : 1, b : 2 `: {false, map[string]string{"a": "1", "b": "2"}},
48 `a : '1' , b : "2"`: {false, map[string]string{"a": "1", "b": "2"}},
49 `" a" : ' 1' , b : "2 " `: {false, map[string]string{" a": " 1", "b": "2 "}}, //nolint:gocritic
50 }
51
52 for name, expected := range testdata {
53 t.Run(name, func(t *testing.T) {
54 t.Parallel()
55
56 r := NewRegistry()
57 m := r.MustNewMetric("metric", Trend)
58 sm, err := m.AddSubmetric(name)
59 if expected.err {
60 require.Error(t, err)
61 return
62 }
63 require.NoError(t, err)
64 require.NotNil(t, sm)
65 assert.EqualValues(t, expected.tags, sm.Tags.Map())
66 })
67 }
68}
69
70func TestParseMetricName(t *testing.T) {
71 t.Parallel()

Callers

nothing calls this directly

Calls 6

MustNewMetricMethod · 0.95
NewRegistryFunction · 0.85
AddSubmetricMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.65
MapMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…