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

Function TestSpanIDAndKindToToken

pkg/util/traceid_test.go:162–202  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

160}
161
162func TestSpanIDAndKindToToken(t *testing.T) {
163 tc := []struct {
164 spanID []byte
165 expected uint64
166 }{
167 {
168 spanID: []byte{0x60, 0xd8, 0xa9, 0xbd},
169 },
170 {
171 spanID: []byte{0x8e, 0xf6, 0x37, 0x90, 0x22, 0x57, 0xb7, 0x43},
172 },
173 {
174 spanID: []byte{0x18, 0xcc, 0xd9, 0x6d, 0x70, 0xc1, 0xbd, 0xf9},
175 },
176 {
177 spanID: []byte{0x8e, 0xf6, 0x37, 0x90, 0x22, 0x57, 0xb7, 0x43, 0xff},
178 },
179 }
180
181 for _, tt := range tc {
182 tokenIDOnly := SpanIDToUint64(tt.spanID)
183 tokensForKind := map[uint64]struct{}{}
184
185 for kind := 0; kind < 8; kind++ {
186 token := SpanIDAndKindToToken(tt.spanID, kind)
187
188 _, exists := tokensForKind[token]
189 assert.False(t, exists, "token expected to be unique for different span kind")
190 assert.NotEqual(t, tokenIDOnly, token)
191 tokensForKind[token] = struct{}{}
192 }
193 }
194
195 t.Run("when kind is outside the boundaries", func(t *testing.T) {
196 spanID := []byte{0x60}
197 t1 := SpanIDAndKindToToken(spanID, 1000)
198 t2 := SpanIDAndKindToToken(spanID, -2)
199
200 assert.Equal(t, t1, t2)
201 })
202}
203
204func TestTokenForID(t *testing.T) {
205 h := NewTokenHasher()

Callers

nothing calls this directly

Calls 4

SpanIDToUint64Function · 0.85
SpanIDAndKindToTokenFunction · 0.85
RunMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected