diff options
author | 2016-10-04 11:05:04 +0100 | |
---|---|---|
committer | 2016-10-04 11:05:04 +0100 | |
commit | db6c9a3f01c9bbef12fd2a1b43e5a84608044ee0 (patch) | |
tree | fab926dc9dab6152a7845313be034c5286d920bb /middleware/metrics/setup_test.go | |
parent | d914832904760e8638bb79189822e2cbe84edee5 (diff) | |
download | coredns-db6c9a3f01c9bbef12fd2a1b43e5a84608044ee0.tar.gz coredns-db6c9a3f01c9bbef12fd2a1b43e5a84608044ee0.tar.zst coredns-db6c9a3f01c9bbef12fd2a1b43e5a84608044ee0.zip |
middleware/metrics: fix crash on startup (#318)
Make the methods that handle Metrics all use pointer receivers to fix
sync.Once not being initialized.
Finish the setup_test to test for failures. And make the check for the
address more strict and return an error when it does not have a port
number.
Add a toplevel test that starts a CoreDNS server with metrics enabled
so we catch these errors in the future.
Diffstat (limited to 'middleware/metrics/setup_test.go')
-rw-r--r-- | middleware/metrics/setup_test.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/middleware/metrics/setup_test.go b/middleware/metrics/setup_test.go index 231830c89..2971634f9 100644 --- a/middleware/metrics/setup_test.go +++ b/middleware/metrics/setup_test.go @@ -10,19 +10,32 @@ func TestPrometheus(t *testing.T) { tests := []struct { input string shouldErr bool + addr string }{ - {`prometheus`, false}, - {`prometheus {}`, false}, // TODO(miek): should be true - {`prometheus /foo`, false}, // TODO(miek): should be true - {`prometheus localhost:53`, false}, + // oks + {`prometheus`, false, "localhost:9153"}, + {`prometheus localhost:53`, false, "localhost:53"}, + // fails + {`prometheus {}`, true, ""}, + {`prometheus /foo`, true, ""}, } for i, test := range tests { c := caddy.NewTestController("dns", test.input) - err := setup(c) + m, err := prometheusParse(c) if test.shouldErr && err == nil { t.Errorf("Test %v: Expected error but found nil", i) + continue } else if !test.shouldErr && err != nil { t.Errorf("Test %v: Expected no error but found error: %v", i, err) + continue + } + + if test.shouldErr { + continue + } + + if test.addr != m.Addr { + t.Errorf("Test %v: Expected address %s but found: %s", i, test.addr, m.Addr) } } } |