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

starter_test.go « starter « bootstrap « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7347d0e13dbcc68439a42de221ea3d7e43eb08e0 (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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package starter

import (
	"errors"
	"testing"

	"github.com/stretchr/testify/require"
)

func TestIsSecure(t *testing.T) {
	for _, test := range []struct {
		name   string
		secure bool
	}{
		{"tcp", false},
		{"unix", false},
		{"tls", true},
	} {
		t.Run(test.name, func(t *testing.T) {
			conf := Config{Name: test.name}
			require.Equal(t, test.secure, conf.isSecure())
		})
	}
}

func TestFamily(t *testing.T) {
	for _, test := range []struct {
		name, family string
	}{
		{"tcp", "tcp"},
		{"unix", "unix"},
		{"tls", "tcp"},
	} {
		t.Run(test.name, func(t *testing.T) {
			conf := Config{Name: test.name}
			require.Equal(t, test.family, conf.family())
		})
	}
}

func TestComposeEndpoint(t *testing.T) {
	for _, tc := range []struct {
		desc   string
		schema string
		addr   string
		exp    string
		expErr error
	}{
		{
			desc:   "no addresses",
			schema: TCP,
			addr:   "",
			expErr: errors.New("empty address can't be used"),
		},
		{
			desc:   "incorrect schema",
			schema: "bad",
			addr:   "127.0.0.1:2306",
			expErr: errors.New(`unsupported schema: "bad"`),
		},
		{
			desc:   "no schema",
			addr:   "127.0.0.1:2306",
			schema: "",
			expErr: errors.New("empty schema can't be used"),
		},
		{
			desc:   "tcp schema addresses",
			schema: TCP,
			addr:   "127.0.0.1:2306",
			exp:    "tcp://127.0.0.1:2306",
		},
		{
			desc:   "tls schema addresses",
			schema: TLS,
			addr:   "127.0.0.1:2306",
			exp:    "tls://127.0.0.1:2306",
		},
		{
			desc:   "unix schema addresses",
			schema: Unix,
			addr:   "/path/to/socket",
			exp:    "unix:///path/to/socket",
		},
	} {
		t.Run(tc.desc, func(t *testing.T) {
			actual, err := ComposeEndpoint(tc.schema, tc.addr)
			require.Equal(t, tc.expErr, err)
			require.Equal(t, tc.exp, actual)
		})
	}
}

func TestParseEndpoint(t *testing.T) {
	for _, tc := range []struct {
		desc   string
		addr   string
		exp    Config
		expErr error
	}{
		{
			desc:   "no addresses",
			expErr: errEmptyAddress,
		},
		{
			desc:   "incorrect schema",
			addr:   "bad://127.0.0.1:2306",
			expErr: errors.New(`unsupported schema: "bad"`),
		},
		{
			desc:   "no schema",
			addr:   "://127.0.0.1:2306",
			expErr: errEmptySchema,
		},
		{
			desc:   "bad format",
			addr:   "127.0.0.1:2306",
			expErr: errors.New(`unsupported format: "127.0.0.1:2306"`),
		},
		{
			desc: "tcp schema addresses",
			addr: "tcp://127.0.0.1:2306",
			exp:  Config{Name: TCP, Addr: "127.0.0.1:2306"},
		},
		{
			desc: "tls schema addresses",
			addr: "tls://127.0.0.1:2306",
			exp:  Config{Name: TLS, Addr: "127.0.0.1:2306"},
		},
		{
			desc: "unix schema addresses",
			addr: "unix:///path/to/socket",
			exp:  Config{Name: Unix, Addr: "/path/to/socket"},
		},
	} {
		t.Run(tc.desc, func(t *testing.T) {
			actual, err := ParseEndpoint(tc.addr)
			require.Equal(t, tc.expErr, err)
			require.Equal(t, tc.exp, actual)
		})
	}
}

func TestConfig_Endpoint(t *testing.T) {
	for _, tc := range []struct {
		desc   string
		conf   Config
		exp    string
		expErr error
	}{
		{
			desc:   "no address",
			conf:   Config{Name: TCP},
			expErr: errors.New("empty address can't be used"),
		},
		{
			desc:   "no schema",
			conf:   Config{Addr: "localhost"},
			expErr: errors.New("empty schema can't be used"),
		},
		{
			desc:   "invalid schema",
			conf:   Config{Name: "invalid", Addr: "localhost"},
			expErr: errors.New(`unsupported schema: "invalid"`),
		},
		{
			desc: "unix",
			conf: Config{Name: Unix, Addr: "/var/opt/some"},
			exp:  "unix:///var/opt/some",
		},
		{
			desc: "tcp",
			conf: Config{Name: TCP, Addr: "localhost:1234"},
			exp:  "tcp://localhost:1234",
		},
		{
			desc: "tls",
			conf: Config{Name: TLS, Addr: "localhost:4321"},
			exp:  "tls://localhost:4321",
		},
	} {
		t.Run(tc.desc, func(t *testing.T) {
			actual, err := tc.conf.Endpoint()
			require.Equal(t, tc.expErr, err)
			require.Equal(t, tc.exp, actual)
		})
	}
}