Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sentryhandler_test.go « sentryhandler « middleware « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b156de4744715086c5563d90e4b068dcc35434e8 (plain)
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
package sentryhandler

import (
	"fmt"
	"testing"
	"time"

	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"

	"github.com/stretchr/testify/assert"
	"golang.org/x/net/context"
)

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,
		},
	}
	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)
		})
	}
}