...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package tracetest
16
17 import (
18 "context"
19 "fmt"
20 "testing"
21
22 "github.com/stretchr/testify/assert"
23 "github.com/stretchr/testify/require"
24 )
25
26
27 func TestNoop(t *testing.T) {
28 nsb := NewNoopExporter()
29
30 require.NoError(t, nsb.ExportSpans(context.Background(), nil))
31 require.NoError(t, nsb.ExportSpans(context.Background(), make(SpanStubs, 10).Snapshots()))
32 require.NoError(t, nsb.ExportSpans(context.Background(), make(SpanStubs, 0, 10).Snapshots()))
33 }
34
35 func TestNewInMemoryExporter(t *testing.T) {
36 imsb := NewInMemoryExporter()
37
38 require.NoError(t, imsb.ExportSpans(context.Background(), nil))
39 assert.Len(t, imsb.GetSpans(), 0)
40
41 input := make(SpanStubs, 10)
42 for i := 0; i < 10; i++ {
43 input[i] = SpanStub{Name: fmt.Sprintf("span %d", i)}
44 }
45 require.NoError(t, imsb.ExportSpans(context.Background(), input.Snapshots()))
46 sds := imsb.GetSpans()
47 assert.Len(t, sds, 10)
48 for i, sd := range sds {
49 assert.Equal(t, input[i], sd)
50 }
51 imsb.Reset()
52
53 assert.Len(t, sds, 10)
54 assert.Len(t, imsb.GetSpans(), 0)
55
56 require.NoError(t, imsb.ExportSpans(context.Background(), input.Snapshots()[0:1]))
57 sds = imsb.GetSpans()
58 assert.Len(t, sds, 1)
59 assert.Equal(t, input[0], sds[0])
60 }
61
View as plain text