mirror of
https://github.com/coredns/coredns.git
synced 2025-11-08 04:56:21 -05:00
middleware/metrics: fix crash (#295)
Fix the crash and add `setup_test.go` to catch this in the future. Fixes #292
This commit is contained in:
@@ -79,6 +79,6 @@ func prometheusParse(c *caddy.Controller) (Metrics, error) {
|
|||||||
return met, err
|
return met, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var metricsOnce *sync.Once
|
var metricsOnce sync.Once
|
||||||
|
|
||||||
const addr = "localhost:9153"
|
const addr = "localhost:9153"
|
||||||
|
|||||||
28
middleware/metrics/setup_test.go
Normal file
28
middleware/metrics/setup_test.go
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package metrics
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/mholt/caddy"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPrometheus(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
input string
|
||||||
|
shouldErr bool
|
||||||
|
}{
|
||||||
|
{`prometheus`, false},
|
||||||
|
{`prometheus {}`, false}, // TODO(miek): should be true
|
||||||
|
{`prometheus /foo`, false}, // TODO(miek): should be true
|
||||||
|
{`prometheus localhost:53`, false},
|
||||||
|
}
|
||||||
|
for i, test := range tests {
|
||||||
|
c := caddy.NewTestController("dns", test.input)
|
||||||
|
err := setup(c)
|
||||||
|
if test.shouldErr && err == nil {
|
||||||
|
t.Errorf("Test %v: Expected error but found nil", i)
|
||||||
|
} else if !test.shouldErr && err != nil {
|
||||||
|
t.Errorf("Test %v: Expected no error but found error: %v", i, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user