-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathconfig_test.go
56 lines (51 loc) · 1.14 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
package main
import (
"testing"
)
func TestValidConfig(t *testing.T) {
const conf = `
[global]
upstream = "https://github.com/miekg/gitopper-config"
mount = "/tmp"
branch = "main"
[[services]]
machine = "localhost"
branch = "canary"
service = "prometheus"
user = "grafana"
package = "grafana"
action = "reload"
dirs = [
{ local = "/etc/prometheus", link = "prometheus/etc" },
]
`
c, err := parseConfig([]byte(conf))
if err != nil {
t.Fatalf("expected to parse config, but got: %s", err)
}
serv := c.Services[0]
serv = serv.merge(c.Global)
if serv.Mount == "" {
t.Errorf("expected service to have Mount, got none")
}
if serv.Upstream == "" {
t.Errorf("expected service to have Upstream, got none")
}
if serv.Branch != "canary" {
t.Errorf("expected Branch to be %s, got %s", "canary", serv.Branch)
}
}
func TestInvalidConfig(t *testing.T) {
const conf = `
[global]
upstream = "https://github.com/miekg/gitopper-config"
mount = "/tmp"
[[services]]
machine = "localhost"
brokenbranch = "main"
service = "prometheus"
`
if _, err := parseConfig([]byte(conf)); err == nil {
t.Fatalf("expected to fail to parse config, but got nil error")
}
}