summaryrefslogtreecommitdiff
path: root/modules/metrics/metrics_test.go
blob: 9eb02fbb3d030e5d0d0ec138474e5b1480164b48 (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
package metrics

import (
	"testing"

	"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
)

func TestMetricsUnmarshalCaddyfile(t *testing.T) {
	m := &Metrics{}
	d := caddyfile.NewTestDispenser(`metrics bogus`)
	err := m.UnmarshalCaddyfile(d)
	if err == nil {
		t.Errorf("expected error")
	}

	m = &Metrics{}
	d = caddyfile.NewTestDispenser(`metrics`)
	err = m.UnmarshalCaddyfile(d)
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	if m.DisableOpenMetrics {
		t.Errorf("DisableOpenMetrics should've been false: %v", m.DisableOpenMetrics)
	}

	m = &Metrics{}
	d = caddyfile.NewTestDispenser(`metrics { disable_openmetrics }`)
	err = m.UnmarshalCaddyfile(d)
	if err != nil {
		t.Errorf("unexpected error: %v", err)
	}

	if !m.DisableOpenMetrics {
		t.Errorf("DisableOpenMetrics should've been true: %v", m.DisableOpenMetrics)
	}

	m = &Metrics{}
	d = caddyfile.NewTestDispenser(`metrics { bogus }`)
	err = m.UnmarshalCaddyfile(d)
	if err == nil {
		t.Errorf("expected error: %v", err)
	}
}