-
Notifications
You must be signed in to change notification settings - Fork 11
/
errors_test.go
58 lines (50 loc) · 1.3 KB
/
errors_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
package otgrpc
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/opentracing/opentracing-go/mocktracer"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const (
firstCode = codes.OK
lastCode = codes.DataLoss
)
func TestSpanTags(t *testing.T) {
t.Parallel()
tracer := mocktracer.New()
for code := firstCode; code <= lastCode; code++ {
// Client error
tracer.Reset()
span := tracer.StartSpan("test-trace-client")
err := status.Error(code, "")
SetSpanTags(span, err, true)
span.Finish()
// Assert added tags
rawSpan := tracer.FinishedSpans()[0]
expectedTags := map[string]interface{}{
"response_code": code,
"response_class": ErrorClass(err),
}
if err != nil && ErrorClass(err) != Success {
expectedTags["error"] = true
}
assert.Equal(t, expectedTags, rawSpan.Tags())
// Server error
tracer.Reset()
span = tracer.StartSpan("test-trace-server")
err = status.Error(code, "")
SetSpanTags(span, err, false)
span.Finish()
// Assert added tags
rawSpan = tracer.FinishedSpans()[0]
expectedTags = map[string]interface{}{
"response_code": code,
"response_class": ErrorClass(err),
}
if err != nil && ErrorClass(err) == ServerError {
expectedTags["error"] = true
}
assert.Equal(t, expectedTags, rawSpan.Tags())
}
}