mirror of
https://github.com/coredns/coredns.git
synced 2025-10-28 08:44:17 -04:00
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:
@@ -1,9 +1,14 @@
|
||||
package view
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/coredns/caddy"
|
||||
ptest "github.com/coredns/coredns/plugin/test"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
)
|
||||
|
||||
func TestSetup(t *testing.T) {
|
||||
@@ -17,6 +22,8 @@ func TestSetup(t *testing.T) {
|
||||
{"view example {\n expr name() == 'example.com.'\n expr name() == 'example2.com.'\n}", false, 2},
|
||||
{"view", true, 0},
|
||||
{"view example {\n expr invalid expression\n}", true, 0},
|
||||
{"view x {\n foo bar\n}\n", true, 0},
|
||||
{"view a { }\nview b { }\n", true, 0},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
@@ -36,3 +43,21 @@ func TestSetup(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeDNS_DelegatesToNext(t *testing.T) {
|
||||
v := &View{}
|
||||
wantCode := 123
|
||||
wantErr := errors.New("boom")
|
||||
v.Next = ptest.NextHandler(wantCode, wantErr)
|
||||
|
||||
rr := new(dns.Msg)
|
||||
rr.SetQuestion("example.com.", dns.TypeA)
|
||||
w := &ptest.ResponseWriter{}
|
||||
gotCode, gotErr := v.ServeDNS(context.Background(), w, rr)
|
||||
if gotCode != wantCode {
|
||||
t.Fatalf("rcode: got %d, want %d", gotCode, wantCode)
|
||||
}
|
||||
if gotErr != wantErr {
|
||||
t.Fatalf("error: got %v, want %v", gotErr, wantErr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user