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

config_test.go « blackbox « internal - gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: fb41a0f2535364f063651026258827e520c0905e (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
package blackbox

import (
	"testing"
	"time"

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

func TestConfigParseFailures(t *testing.T) {
	testCases := []struct {
		desc string
		in   string
	}{
		{desc: "empty config"},
		{desc: "probe without name", in: "[[probe]]\n"},
		{desc: "unsupported probe url", in: "[[probe]]\nname='foo'\nurl='ssh://not:supported'"},
		{desc: "missing probe url", in: "[[probe]]\nname='foo'\n"},
		{desc: "negative sleep", in: "sleep=-1\n[[probe]]\nname='foo'\nurl='http://foo/bar'"},
		{desc: "no listen addr", in: "[[probe]]\nname='foo'\nurl='http://foo/bar'"},
	}

	for _, tc := range testCases {
		t.Run(tc.desc, func(t *testing.T) {
			_, err := ParseConfig(tc.in)

			require.Error(t, err, "expect parse error")
		})
	}
}

func TestConfigSleep(t *testing.T) {
	testCases := []struct {
		desc string
		in   string
		out  time.Duration
	}{
		{
			desc: "default sleep time",
			out:  15 * time.Minute,
		},
		{
			desc: "1 second",
			in:   "sleep = 1\n",
			out:  time.Second,
		},
	}

	const validConfig = `
prometheus_listen_addr = ':9687'
[[probe]]
name = 'foo'
url = 'http://foo/bar'
`
	for _, tc := range testCases {
		t.Run(tc.desc, func(t *testing.T) {
			cfg, err := ParseConfig(tc.in + validConfig)
			require.NoError(t, err, "parse config")

			require.Equal(t, tc.out, cfg.SleepDuration, "parsed sleep time")
		})
	}
}