This repository has been archived by the owner on May 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 288
/
context_test.go
62 lines (55 loc) · 1.76 KB
/
context_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package jaeger
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestContextFromString(t *testing.T) {
var err error
_, err = ContextFromString("")
assert.Error(t, err)
_, err = ContextFromString("abcd")
assert.Error(t, err)
_, err = ContextFromString("x:1:1:1")
assert.Error(t, err)
_, err = ContextFromString("1:x:1:1")
assert.Error(t, err)
_, err = ContextFromString("1:1:x:1")
assert.Error(t, err)
_, err = ContextFromString("1:1:1:x")
assert.Error(t, err)
_, err = ContextFromString("1:1:1:x")
assert.Error(t, err)
ctx, err := ContextFromString("1:1:1:1")
assert.NoError(t, err)
assert.EqualValues(t, 1, ctx.traceID)
assert.EqualValues(t, 1, ctx.spanID)
assert.EqualValues(t, 1, ctx.parentID)
assert.EqualValues(t, 1, ctx.flags)
ctx = NewSpanContext(1, 1, 1, true, nil)
assert.EqualValues(t, 1, ctx.traceID)
assert.EqualValues(t, 1, ctx.spanID)
assert.EqualValues(t, 1, ctx.parentID)
assert.EqualValues(t, 1, ctx.flags)
}
func TestSpanContext_WithBaggageItem(t *testing.T) {
var ctx SpanContext
ctx = ctx.WithBaggageItem("some-KEY", "Some-Value")
assert.Equal(t, map[string]string{"some-KEY": "Some-Value"}, ctx.baggage)
ctx = ctx.WithBaggageItem("some-KEY", "Some-Other-Value")
assert.Equal(t, map[string]string{"some-KEY": "Some-Other-Value"}, ctx.baggage)
}
func TestSpanContext_SampledDebug(t *testing.T) {
ctx, err := ContextFromString("1:1:1:1")
require.NoError(t, err)
assert.True(t, ctx.IsSampled())
assert.False(t, ctx.IsDebug())
ctx, err = ContextFromString("1:1:1:3")
require.NoError(t, err)
assert.True(t, ctx.IsSampled())
assert.True(t, ctx.IsDebug())
ctx, err = ContextFromString("1:1:1:0")
require.NoError(t, err)
assert.False(t, ctx.IsSampled())
assert.False(t, ctx.IsDebug())
}