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
|
package main
import (
"bytes"
"io"
"os/exec"
"strings"
"testing"
"github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/v15/internal/testhelper/testcfg"
)
func TestValidateConfiguration(t *testing.T) {
t.Parallel()
cfg := testcfg.Build(t)
testcfg.BuildGitaly(t, cfg)
for _, tc := range []struct {
name string
exitCode int
stdin func(t *testing.T) io.Reader
stderr string
stdout string
}{
{
name: "ok",
exitCode: 0,
stdin: func(*testing.T) io.Reader {
t.Helper()
var stdin bytes.Buffer
require.NoError(t, toml.NewEncoder(&stdin).Encode(cfg))
return &stdin
},
},
{
name: "bad toml format",
exitCode: 1,
stdin: func(*testing.T) io.Reader {
return strings.NewReader(`graceful_restart_timeout = "bad value"`)
},
stdout: `{
"errors": [
{
"message": "line 1 column 28: toml: time: invalid duration \"bad value\""
}
]
}
`,
},
{
name: "validation failures",
exitCode: 1,
stdin: func(t *testing.T) io.Reader {
cfg := cfg
cfg.Git.Config = []config.GitConfig{{Key: "bad"}}
cfg.Storages = []config.Storage{{Name: " ", Path: cfg.Storages[0].Path}}
var stdin bytes.Buffer
require.NoError(t, toml.NewEncoder(&stdin).Encode(cfg))
return &stdin
},
stdout: `{
"errors": [
{
"key": [
"storage",
"name"
],
"message": "empty value at declaration 1"
},
{
"key": [
"git",
"config"
],
"message": "invalid configuration key 'bad': key must contain at least one section"
}
]
}
`,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
cmd := exec.Command(cfg.BinaryPath("gitaly"), "validate-configuration")
var stderr, stdout bytes.Buffer
cmd.Stderr = &stderr
cmd.Stdout = &stdout
cmd.Stdin = tc.stdin(t)
err := cmd.Run()
if tc.exitCode != 0 {
status, ok := command.ExitStatus(err)
require.Truef(t, ok, "%T: %v", err, err)
assert.Equal(t, tc.exitCode, status)
}
assert.Equal(t, tc.stderr, stderr.String())
assert.Equal(t, tc.stdout, stdout.String())
})
}
}
|