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
|
package config
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/praefect/models"
)
func TestConfigValidation(t *testing.T) {
nodes := []*models.StorageNode{
{ID: 1, Address: "localhost:23456", Token: "secret-token"},
{ID: 2, Address: "localhost:23457", Token: "secret-token"},
{ID: 3, Address: "localhost:23458", Token: "secret-token"},
}
testCases := []struct {
desc string
config Config
err error
}{
{
desc: "No ListenAddr or SocketPath",
config: Config{ListenAddr: "", StorageNodes: nodes},
err: errNoListener,
},
{
desc: "Only a SocketPath",
config: Config{SocketPath: "/tmp/praefect.socket", StorageNodes: nodes},
err: nil,
},
{
desc: "No servers",
config: Config{ListenAddr: "localhost:1234"},
err: errNoGitalyServers,
},
{
desc: "duplicate address",
config: Config{ListenAddr: "localhost:1234", StorageNodes: append(nodes, &models.StorageNode{Address: nodes[0].Address})},
err: errDuplicateGitalyAddr,
},
{
desc: "Valid config",
config: Config{ListenAddr: "localhost:1234", StorageNodes: nodes},
err: nil,
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
err := tc.config.Validate()
assert.Equal(t, tc.err, err)
})
}
}
func TestConfigParsing(t *testing.T) {
testCases := []struct {
filePath string
expected Config
}{
{
filePath: "testdata/config.toml",
expected: Config{
StorageNodes: []*models.StorageNode{
{
Address: "tcp://gitaly-internal-1.example.com",
Storage: "praefect-internal-1",
},
{
Address: "tcp://gitaly-internal-2.example.com",
Storage: "praefect-internal-2",
},
{
Address: "tcp://gitaly-internal-3.example.com",
Storage: "praefect-internal-3",
},
},
Whitelist: []string{"abcd1234", "edfg5678"},
},
},
}
for _, tc := range testCases {
t.Run(tc.filePath, func(t *testing.T) {
cfg, err := FromFile(tc.filePath)
require.NoError(t, err)
require.Equal(t, tc.expected, cfg)
})
}
}
|