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:
Miek Gieben
2016-09-24 22:47:38 +01:00
committed by GitHub
parent 1ad02e8639
commit edc867fe56
2 changed files with 29 additions and 1 deletions

View 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)
}
}
}