fix: use descriptive error for unknown block options in health and log plugins (#8128)

This commit is contained in:
Immanuel Tikhonov
2026-05-28 03:29:24 +04:00
committed by GitHub
parent afdf121a5a
commit 0bcb17df06
4 changed files with 29 additions and 12 deletions

View File

@@ -1,6 +1,7 @@
package health
import (
"strings"
"testing"
"github.com/coredns/caddy"
@@ -8,24 +9,25 @@ import (
func TestSetupHealth(t *testing.T) {
tests := []struct {
input string
shouldErr bool
input string
shouldErr bool
expectedErrContent string
}{
{`health`, false},
{`health localhost:1234`, false},
{`health`, false, ""},
{`health localhost:1234`, false, ""},
{`health localhost:1234 {
lameduck 4s
}`, false},
{`health bla:a`, false},
}`, false, ""},
{`health bla:a`, false, ""},
{`health bla`, true},
{`health bla bla`, true},
{`health bla`, true, ""},
{`health bla bla`, true, ""},
{`health localhost:1234 {
lameduck a
}`, true},
}`, true, ""},
{`health localhost:1234 {
lamedudk 4
} `, true},
} `, true, "unknown property"},
}
for i, test := range tests {
@@ -40,6 +42,9 @@ func TestSetupHealth(t *testing.T) {
if !test.shouldErr {
t.Errorf("Test %d: Expected no error but found one for input %s. Error was: %v", i, test.input, err)
}
if test.expectedErrContent != "" && !strings.Contains(err.Error(), test.expectedErrContent) {
t.Errorf("Test %d: Expected error to contain %q, got: %v", i, test.expectedErrContent, err)
}
}
}
}