-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_test.go
47 lines (42 loc) · 1.13 KB
/
setup_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
package prommetrics
import (
"testing"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/caddy/v2/caddyconfig/httpcaddyfile"
)
func TestParse(t *testing.T) {
tests := []struct {
input string
shouldErr bool
expected Metrics
}{
{`prometheus`, false, Metrics{regex: defaultRegex}},
{`prometheus {
a b
}`, true, Metrics{}},
{`prometheus prometheus`, true, Metrics{}},
{`prometheus {
regex "^https?://([^\/]+).*$"
}`, false, Metrics{regex: `^https?://([^\/]+).*$`}},
}
for i, test := range tests {
h := httpcaddyfile.Helper{
Dispenser: caddyfile.NewTestDispenser(test.input),
}
actual, err := parseCaddyfile(h)
got := actual.(Metrics)
got.Provision(caddy.Context{})
if test.shouldErr {
if err == nil {
t.Errorf("Test %v: Expected error but found nil", i)
}
} else {
if err != nil {
t.Errorf("Test %v: Expected no error but found error: %v", i, err)
} else if test.expected.regex != got.regex {
t.Errorf("Test %v: Created Metrics (\n%#v\n) does not match expected (\n%#v\n)", i, got, test.expected)
}
}
}
}