summaryrefslogtreecommitdiff
path: root/go/cmd/gitaly-upload-pack/main_test.go
blob: 4fa3e07efb15e142ebd4f23cbb8d205db0e72aee (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
package main

import (
	"testing"

	"github.com/stretchr/testify/require"
	pb "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)

func Test_deserialize(t *testing.T) {
	tests := []struct {
		name        string
		requestJSON string
		want        *pb.SSHUploadPackRequest
		wantErr     bool
	}{
		{
			name:        "empty",
			requestJSON: "",
			want:        nil,
			wantErr:     true,
		},
		{
			name:        "empty_hash",
			requestJSON: "{}",
			want:        &pb.SSHUploadPackRequest{},
			wantErr:     false,
		},
		{
			name:        "nil",
			requestJSON: "null",
			want:        &pb.SSHUploadPackRequest{},
			wantErr:     false,
		},
		{
			name:        "values",
			requestJSON: `{"repository": { "storage_name": "12345"} }`,
			want:        &pb.SSHUploadPackRequest{Repository: &pb.Repository{StorageName: "12345"}},
			wantErr:     false,
		},
		{
			name:        "invalid_json",
			requestJSON: `{"gl_id": "1234`,
			want:        nil,
			wantErr:     true,
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got, err := deserialize(tt.requestJSON)
			require.EqualValues(t, got, tt.want, "Got %+v, wanted %+v", got, tt.want)
			if tt.wantErr {
				require.Error(t, err, "Wanted an error, got %+v", err)
			} else {
				require.NoError(t, err, "Wanted no error, got %+v", err)
			}
		})
	}
}