forked from stripe/veneur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
regression_test.go
107 lines (91 loc) · 2.57 KB
/
regression_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
package veneur
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
proto "github.com/golang/protobuf/proto"
"github.com/stripe/veneur/protocol"
"github.com/stripe/veneur/ssf"
)
func validSample() ssf.SSFSpan {
return *&ssf.SSFSpan{
TraceId: 1,
Id: 1,
StartTimestamp: 1,
EndTimestamp: 10,
}
}
// Tests that setting the tag "Name" will result in a span with span.Name being set,
// and the tag "Name" being deleted.
func TestTagNameSetNameNotSet(t *testing.T) {
sample := validSample()
sample.Tags = make(map[string]string)
sample.Tags["name"] = "testName"
buf, err := proto.Marshal(&sample)
assert.NoError(t, err, "Eror when marshalling sample")
span, errSSF := protocol.ParseSSF(buf)
assert.NoError(t, err)
if assert.NotNil(t, span) {
assert.NoError(t, err)
if assert.NotNil(t, span) {
assert.Equal(t, sample.Tags["name"], span.Name, "Name via Tag did not propogate")
assert.NoError(t, errSSF)
assert.Empty(t, span.Tags["name"])
}
}
}
// Tests that setting a tag "Name" and span.Name won't change
// span.Name to be the tag "Name", and that the tag is still there
// after we parse the packet.
func TestTagNameSetNameSet(t *testing.T) {
sample := validSample()
sample.Tags = make(map[string]string)
sample.Tags["name"] = "testName"
sample.Name = "realName"
buf, err := proto.Marshal(&sample)
assert.NoError(t, err, "Error when marshalling sample")
span, errSSF := protocol.ParseSSF(buf)
assert.NoError(t, err)
if assert.NotNil(t, span) {
assert.NoError(t, err)
if assert.NotNil(t, span) {
assert.Equal(t, sample.Name, span.Name, "Name did not propogate")
assert.NoError(t, errSSF)
assert.NotEmpty(t, span.Tags["name"])
}
}
}
func TestNoTagName(t *testing.T) {
sample := validSample()
sample.Name = "realName"
buf, err := proto.Marshal(&sample)
assert.NoError(t, err)
span, errSSF := protocol.ParseSSF(buf)
assert.NoError(t, err)
if assert.NotNil(t, span) {
assert.NoError(t, err)
if assert.NotNil(t, span) {
assert.Equal(t, sample.Name, span.Name, "Name did not propogate")
assert.NoError(t, errSSF)
}
}
}
func TestOperation(t *testing.T) {
pbFile := filepath.Join("testdata", "protobuf", "span-with-operation-062017.pb")
pb, err := os.Open(pbFile)
assert.NoError(t, err)
defer pb.Close()
packet, err := ioutil.ReadAll(pb)
assert.NoError(t, err)
span, errSSF := protocol.ParseSSF(packet)
assert.NoError(t, errSSF)
if assert.NotNil(t, span) {
assert.NoError(t, err)
if assert.NotNil(t, span) {
assert.NoError(t, errSSF)
assert.NotNil(t, span)
}
}
}