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
|
package sentryhandler
import (
"context"
"fmt"
"testing"
"time"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func Test_generateRavenPacket(t *testing.T) {
tests := []struct {
name string
method string
sinceStart time.Duration
wantNil bool
err error
wantCode codes.Code
wantMessage string
wantCulprit string
}{
{
name: "internal error",
method: "/gitaly.SSHService/SSHUploadPack",
sinceStart: 500 * time.Millisecond,
err: fmt.Errorf("Internal"),
wantCode: codes.Unknown,
wantMessage: "Internal",
wantCulprit: "SSHService::SSHUploadPack",
},
{
name: "GRPC error",
method: "/gitaly.RepoService/RepoExists",
sinceStart: 500 * time.Millisecond,
err: status.Errorf(codes.NotFound, "Something failed"),
wantCode: codes.NotFound,
wantMessage: "rpc error: code = NotFound desc = Something failed",
wantCulprit: "RepoService::RepoExists",
},
{
name: "nil",
method: "/gitaly.RepoService/RepoExists",
sinceStart: 500 * time.Millisecond,
err: nil,
wantNil: true,
},
{
name: "Canceled",
method: "/gitaly.RepoService/RepoExists",
sinceStart: 500 * time.Millisecond,
err: status.Errorf(codes.Canceled, "Something failed"),
wantNil: true,
},
{
name: "DeadlineExceeded",
method: "/gitaly.RepoService/RepoExists",
sinceStart: 500 * time.Millisecond,
err: status.Errorf(codes.DeadlineExceeded, "Something failed"),
wantNil: true,
},
{
name: "FailedPrecondition",
method: "/gitaly.RepoService/RepoExists",
sinceStart: 500 * time.Millisecond,
err: status.Errorf(codes.FailedPrecondition, "Something failed"),
wantNil: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
start := time.Now().Add(-tt.sinceStart)
packet, tags := generateRavenPacket(context.Background(), tt.method, start, tt.err)
if tt.wantNil {
assert.Nil(t, packet)
return
}
assert.Equal(t, tt.wantCulprit, packet.Culprit)
assert.Equal(t, tt.wantMessage, packet.Message)
assert.Equal(t, tags["system"], "grpc")
assert.NotEmpty(t, tags["grpc.time_ms"])
assert.Equal(t, tt.method, tags["grpc.method"])
assert.Equal(t, tt.wantCode.String(), tags["grpc.code"])
assert.Equal(t, []string{"grpc", tt.wantCulprit, tt.wantCode.String()}, packet.Fingerprint)
})
}
}
|