-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathconfig_test.go
57 lines (44 loc) · 1.39 KB
/
config_test.go
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
package main
import (
"github.com/pelletier/go-toml/v2"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
func TestMergeConfig(t *testing.T) {
config := parseDefaultConfig()
minimalConfig := `bind = "1.1.1.1:5301" `
if err := toml.Unmarshal([]byte(minimalConfig), &config); err != nil {
t.Fatalf("should parse config\n%v", err)
}
assert.Equal(t, "1.1.1.1:5301", config.Bind, "expected overridden value for config.bind")
}
func TestMetricsNested(t *testing.T) {
config := parseDefaultConfig()
assert.Equal(t, false, config.Metrics.Enabled, "expected metrics off by default")
assert.Equal(t, "/metrics", config.Metrics.Path, "expected metrics off by default")
minimalConfig := `
[metrics]
enabled = true
path = "/voo"
`
if err := toml.Unmarshal([]byte(minimalConfig), &config); err != nil {
t.Fatalf("should parse config\n%v\n", err)
}
assert.Equal(t, true, config.Metrics.Enabled, "expected overridden value for config.bind")
}
func TestFriendlyErrors(t *testing.T) {
config := parseDefaultConfig()
badConfig := `
[metrics]
enabled = 3
`
err := toml.Unmarshal([]byte(badConfig), &config)
if err == nil {
t.Fatalf("expected an error!")
}
err = contextualisedParsingErrorFrom(err)
if !(strings.Contains(err.Error(), "enabled = 3") && strings.Contains(err.Error(), "row 3 column 11")) {
t.Fatalf("expected error string to contain contextual info, but was %v", err.Error())
}
}