From 31d40d0b403aad17e7bdeba46eac63600e2713c5 Mon Sep 17 00:00:00 2001 From: vnxme <46669194+vnxme@users.noreply.github.com> Date: Fri, 16 Aug 2024 23:22:18 +0300 Subject: [PATCH] Adjust matchers after #208: modify error handling in tests --- modules/l4dns/matcher_test.go | 6 +++++- modules/l4rdp/matcher_test.go | 3 ++- modules/l4regexp/matcher_test.go | 6 ++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/l4dns/matcher_test.go b/modules/l4dns/matcher_test.go index 45645fe..19d890a 100644 --- a/modules/l4dns/matcher_test.go +++ b/modules/l4dns/matcher_test.go @@ -16,6 +16,8 @@ package l4dns import ( "context" + "errors" + "fmt" "io" "net" "testing" @@ -28,7 +30,7 @@ import ( func assertNoError(t *testing.T, err error) { t.Helper() - if err != nil { + if err != nil && !errors.Is(err, io.EOF) && !errors.Is(err, io.ErrUnexpectedEOF) { t.Fatalf("Unexpected error: %s\n", err) } } @@ -42,6 +44,7 @@ func Test_MatchDNS_Match(t *testing.T) { } tests := []test{ + {matcher: &MatchDNS{}, data: []byte{}, shouldMatch: false, shouldFakeTCP: true}, {matcher: &MatchDNS{}, data: []byte{}, shouldMatch: false}, {matcher: &MatchDNS{}, data: udpPacketAppleComA[:12], shouldMatch: false}, @@ -114,6 +117,7 @@ func Test_MatchDNS_Match(t *testing.T) { }() matched, err := tc.matcher.Match(cx) + fmt.Println(i) assertNoError(t, err) if matched != tc.shouldMatch { diff --git a/modules/l4rdp/matcher_test.go b/modules/l4rdp/matcher_test.go index 594cdb3..00cb0c4 100644 --- a/modules/l4rdp/matcher_test.go +++ b/modules/l4rdp/matcher_test.go @@ -17,6 +17,7 @@ package l4rdp import ( "bytes" "context" + "errors" "io" "net" "testing" @@ -29,7 +30,7 @@ import ( func assertNoError(t *testing.T, err error) { t.Helper() - if err != nil { + if err != nil && !errors.Is(err, io.EOF) && !errors.Is(err, io.ErrUnexpectedEOF) { t.Fatalf("Unexpected error: %s\n", err) } } diff --git a/modules/l4regexp/matcher_test.go b/modules/l4regexp/matcher_test.go index 0acc14b..b34b8bc 100644 --- a/modules/l4regexp/matcher_test.go +++ b/modules/l4regexp/matcher_test.go @@ -16,18 +16,20 @@ package l4regexp import ( "context" + "errors" "io" "net" "testing" "github.com/caddyserver/caddy/v2" - "github.com/mholt/caddy-l4/layer4" "go.uber.org/zap" + + "github.com/mholt/caddy-l4/layer4" ) func assertNoError(t *testing.T, err error) { t.Helper() - if err != nil { + if err != nil && !errors.Is(err, io.EOF) && !errors.Is(err, io.ErrUnexpectedEOF) { t.Fatalf("Unexpected error: %s\n", err) } }