forked from SumoLogic/telegraf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_test.go
135 lines (123 loc) · 3.25 KB
/
handler_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package zipkin
import (
"bytes"
"io/ioutil"
"net/http"
"net/http/httptest"
"strconv"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/influxdata/telegraf/plugins/inputs/zipkin/trace"
)
type MockRecorder struct {
Data trace.Trace
Err error
}
func (m *MockRecorder) Record(t trace.Trace) error {
m.Data = t
return nil
}
func (m *MockRecorder) Error(err error) {
m.Err = err
}
func TestSpanHandler(t *testing.T) {
dat, err := ioutil.ReadFile("testdata/threespans.dat")
if err != nil {
t.Fatalf("Could not find file %s\n", "testdata/threespans.dat")
}
w := httptest.NewRecorder()
r := httptest.NewRequest(
"POST",
"http://server.local/api/v1/spans",
ioutil.NopCloser(
bytes.NewReader(dat)))
r.Header.Set("Content-Type", "application/x-thrift")
handler := NewSpanHandler("/api/v1/spans")
mockRecorder := &MockRecorder{}
handler.recorder = mockRecorder
handler.Spans(w, r)
if w.Code != http.StatusNoContent {
t.Errorf("MainHandler did not return StatusNoContent %d", w.Code)
}
got := mockRecorder.Data
parentID := strconv.FormatInt(22964302721410078, 16)
want := trace.Trace{
{
Name: "Child",
ID: "7047c59776af8a1b",
TraceID: "22c4fc8ab3669045",
ParentID: parentID,
Timestamp: time.Unix(0, 1498688360851331*int64(time.Microsecond)).UTC(),
Duration: time.Duration(53106) * time.Microsecond,
ServiceName: "trivial",
Annotations: []trace.Annotation{},
BinaryAnnotations: []trace.BinaryAnnotation{
{
Key: "lc",
Value: "trivial",
Host: "127.0.0.1",
ServiceName: "trivial",
},
},
},
{
Name: "Child",
ID: "17020eb55a8bfe5",
TraceID: "22c4fc8ab3669045",
ParentID: parentID,
Timestamp: time.Unix(0, 1498688360904552*int64(time.Microsecond)).UTC(),
Duration: time.Duration(50410) * time.Microsecond,
ServiceName: "trivial",
Annotations: []trace.Annotation{},
BinaryAnnotations: []trace.BinaryAnnotation{
{
Key: "lc",
Value: "trivial",
Host: "127.0.0.1",
ServiceName: "trivial",
},
},
},
{
Name: "Parent",
ID: "5195e96239641e",
TraceID: "22c4fc8ab3669045",
ParentID: parentID,
Timestamp: time.Unix(0, 1498688360851318*int64(time.Microsecond)).UTC(),
Duration: time.Duration(103680) * time.Microsecond,
ServiceName: "trivial",
Annotations: []trace.Annotation{
{
Timestamp: time.Unix(0, 1498688360851325*int64(time.Microsecond)).UTC(),
Value: "Starting child #0",
Host: "127.0.0.1",
ServiceName: "trivial",
},
{
Timestamp: time.Unix(0, 1498688360904545*int64(time.Microsecond)).UTC(),
Value: "Starting child #1",
Host: "127.0.0.1",
ServiceName: "trivial",
},
{
Timestamp: time.Unix(0, 1498688360954992*int64(time.Microsecond)).UTC(),
Value: "A Log",
Host: "127.0.0.1",
ServiceName: "trivial",
},
},
BinaryAnnotations: []trace.BinaryAnnotation{
{
Key: "lc",
Value: "trivial",
Host: "127.0.0.1",
ServiceName: "trivial",
},
},
},
}
if !cmp.Equal(got, want) {
t.Fatalf("Got != Want\n %s", cmp.Diff(got, want))
}
}