forked from hairyhenderson/caddyprom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaddyprom_test.go
66 lines (60 loc) · 1.4 KB
/
caddyprom_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
58
59
60
61
62
63
64
65
66
package caddyprom
import (
"fmt"
"testing"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/stretchr/testify/assert"
)
func TestUnmarshalCaddyfile(t *testing.T) {
metrics := &Metrics{}
dispenser := caddyfile.NewTestDispenser(
`prometheus 0.0.0.0:1337 {
address 0.0.0.0:1337
}`)
assert.Error(t, metrics.UnmarshalCaddyfile(dispenser))
dispenser = caddyfile.NewTestDispenser(
`prometheus {
bogus
}`)
assert.Error(t, metrics.UnmarshalCaddyfile(dispenser))
testdata := []struct {
caddyfile string
expected *Metrics
}{
{
`prometheus`,
&Metrics{Addr: "localhost:9180", Path: "/metrics"},
},
{
`prometheus 0.0.0.0:1337`,
&Metrics{Addr: "0.0.0.0:1337", Path: "/metrics"},
},
{
`prometheus {
address 0.0.0.0:1337
}`,
&Metrics{Addr: "0.0.0.0:1337", Path: "/metrics"},
},
{
`prometheus 0.0.0.0:1337 {
path /otherpath
}`,
&Metrics{Addr: "0.0.0.0:1337", Path: "/otherpath"},
},
{
`prometheus {
address 0.0.0.0:1337
path /otherpath
}`,
&Metrics{Addr: "0.0.0.0:1337", Path: "/otherpath"},
},
}
for i, d := range testdata {
t.Run(fmt.Sprintf("case_%d", i), func(t *testing.T) {
metrics := &Metrics{Addr: "localhost:9180", Path: "/metrics"}
dispenser := caddyfile.NewTestDispenser(d.caddyfile)
assert.NoError(t, metrics.UnmarshalCaddyfile(dispenser))
assert.EqualValues(t, d.expected, metrics)
})
}
}