Skip to content

Commit

Permalink
Adjust matchers after #208: modify error handling in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vnxme committed Aug 16, 2024
1 parent e350826 commit 31d40d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 5 additions & 1 deletion modules/l4dns/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package l4dns

import (
"context"
"errors"
"fmt"
"io"
"net"
"testing"
Expand All @@ -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)
}
}
Expand All @@ -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},
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion modules/l4rdp/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package l4rdp
import (
"bytes"
"context"
"errors"
"io"
"net"
"testing"
Expand All @@ -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)
}
}
Expand Down
6 changes: 4 additions & 2 deletions modules/l4regexp/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 31d40d0

Please sign in to comment.