2017-08-27 21:33:38 +01:00
|
|
|
package health
|
|
|
|
|
|
|
|
|
|
import (
|
2026-05-28 03:29:24 +04:00
|
|
|
"strings"
|
2017-08-27 21:33:38 +01:00
|
|
|
"testing"
|
|
|
|
|
|
2020-09-24 18:14:41 +02:00
|
|
|
"github.com/coredns/caddy"
|
2017-08-27 21:33:38 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestSetupHealth(t *testing.T) {
|
|
|
|
|
tests := []struct {
|
2026-05-28 03:29:24 +04:00
|
|
|
input string
|
|
|
|
|
shouldErr bool
|
|
|
|
|
expectedErrContent string
|
2017-08-27 21:33:38 +01:00
|
|
|
}{
|
2026-05-28 03:29:24 +04:00
|
|
|
{`health`, false, ""},
|
|
|
|
|
{`health localhost:1234`, false, ""},
|
2018-01-18 10:40:09 +00:00
|
|
|
{`health localhost:1234 {
|
|
|
|
|
lameduck 4s
|
2026-05-28 03:29:24 +04:00
|
|
|
}`, false, ""},
|
|
|
|
|
{`health bla:a`, false, ""},
|
2018-01-18 10:40:09 +00:00
|
|
|
|
2026-05-28 03:29:24 +04:00
|
|
|
{`health bla`, true, ""},
|
|
|
|
|
{`health bla bla`, true, ""},
|
2018-01-18 10:40:09 +00:00
|
|
|
{`health localhost:1234 {
|
|
|
|
|
lameduck a
|
2026-05-28 03:29:24 +04:00
|
|
|
}`, true, ""},
|
2018-01-18 10:40:09 +00:00
|
|
|
{`health localhost:1234 {
|
|
|
|
|
lamedudk 4
|
2026-05-28 03:29:24 +04:00
|
|
|
} `, true, "unknown property"},
|
2017-08-27 21:33:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for i, test := range tests {
|
|
|
|
|
c := caddy.NewTestController("dns", test.input)
|
2019-05-04 21:06:04 +01:00
|
|
|
_, _, err := parse(c)
|
2017-08-27 21:33:38 +01:00
|
|
|
|
|
|
|
|
if test.shouldErr && err == nil {
|
2018-01-18 10:40:09 +00:00
|
|
|
t.Errorf("Test %d: Expected error but found none for input %s", i, test.input)
|
2017-08-27 21:33:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
if !test.shouldErr {
|
|
|
|
|
t.Errorf("Test %d: Expected no error but found one for input %s. Error was: %v", i, test.input, err)
|
|
|
|
|
}
|
2026-05-28 03:29:24 +04:00
|
|
|
if test.expectedErrContent != "" && !strings.Contains(err.Error(), test.expectedErrContent) {
|
|
|
|
|
t.Errorf("Test %d: Expected error to contain %q, got: %v", i, test.expectedErrContent, err)
|
|
|
|
|
}
|
2017-08-27 21:33:38 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|