MCPcopy
hub / github.com/grafana/tempo / TestScopedDistinctDiff

Function TestScopedDistinctDiff

pkg/collector/scoped_distinct_string_test.go:95–143  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

93}
94
95func TestScopedDistinctDiff(t *testing.T) {
96 c := NewScopedDistinctStringWithDiff(0, 0, 0)
97
98 c.Collect("scope1", "val1")
99 expected := map[string][]string{
100 "scope1": {"val1"},
101 }
102 assertMaps(t, expected, readScopedDistinctStringDiff(t, c))
103
104 // no diff
105 c.Collect("scope1", "val1")
106 expected = map[string][]string{}
107 assertMaps(t, expected, readScopedDistinctStringDiff(t, c))
108 assertMaps(t, map[string][]string{}, readScopedDistinctStringDiff(t, c))
109
110 // new value
111 c.Collect("scope1", "val2")
112 expected = map[string][]string{
113 "scope1": {"val2"},
114 }
115 assertMaps(t, expected, readScopedDistinctStringDiff(t, c))
116 assertMaps(t, map[string][]string{}, readScopedDistinctStringDiff(t, c))
117
118 // new scope
119 c.Collect("scope2", "val1")
120 expected = map[string][]string{
121 "scope2": {"val1"},
122 }
123 assertMaps(t, expected, readScopedDistinctStringDiff(t, c))
124 assertMaps(t, map[string][]string{}, readScopedDistinctStringDiff(t, c))
125
126 // all
127 c.Collect("scope2", "val1")
128 c.Collect("scope2", "val2")
129 c.Collect("scope1", "val3")
130 expected = map[string][]string{
131 "scope1": {"val3"},
132 "scope2": {"val2"},
133 }
134 assertMaps(t, expected, readScopedDistinctStringDiff(t, c))
135 assertMaps(t, map[string][]string{}, readScopedDistinctStringDiff(t, c))
136
137 // diff should error when diff is not enabled
138 col := NewScopedDistinctString(0, 0, 0)
139 col.Collect("scope1", "val1")
140 res, err := col.Diff()
141 require.Nil(t, res)
142 require.Error(t, err, errDiffNotEnabled)
143}
144
145func readScopedDistinctStringDiff(t *testing.T, d *ScopedDistinctString) map[string][]string {
146 res, err := d.Diff()

Callers

nothing calls this directly

Calls 8

CollectMethod · 0.95
DiffMethod · 0.95
assertMapsFunction · 0.85
NewScopedDistinctStringFunction · 0.85
CollectMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected