test(view): improve test coverage (#7543)

Cover edge cases in config parser. Add rudimentary View/Filter
tests. Improves test coverage from 44% to 82%.

Signed-off-by: Ville Vesilehto <ville@vesilehto.fi>
This commit is contained in:
Ville Vesilehto
2025-09-15 20:17:35 +03:00
committed by GitHub
parent c916cf4259
commit a30954ea71
3 changed files with 118 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package view
import (
"context"
"testing"
"github.com/coredns/coredns/plugin/metadata"
"github.com/coredns/coredns/request"
)
func TestMetadata_PublishesViewName(t *testing.T) {
v := &View{viewName: "myview"}
ctx := metadata.ContextWithMetadata(context.Background())
st := request.Request{}
ctx = v.Metadata(ctx, st)
if f := metadata.ValueFunc(ctx, "view/name"); f == nil {
t.Fatalf("metadata value func is nil")
} else if got := f(); got != "myview" {
t.Fatalf("metadata value: got %q, want %q", got, "myview")
}
}