Skip to content

Commit

Permalink
test: proper use of t.Run in socks matcher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ydylla committed Aug 5, 2024
1 parent 2ebc531 commit d110e3e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions modules/l4socks/socks4_matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package l4socks

import (
"context"
"fmt"
"io"
"net"
"testing"
Expand Down Expand Up @@ -67,7 +68,7 @@ func TestSocks4Matcher_Match(t *testing.T) {
defer cancel()

for i, tc := range tests {
func() {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
err := tc.matcher.Provision(ctx)
assertNoError(t, err)

Expand All @@ -89,12 +90,12 @@ func TestSocks4Matcher_Match(t *testing.T) {

if matched != tc.shouldMatch {
if tc.shouldMatch {
t.Fatalf("test %d: matcher did not match | %+v\n", i, tc.matcher)
t.Fatalf("matcher did not match | %+v\n", tc.matcher)
} else {
t.Fatalf("test %d: matcher should not match | %+v\n", i, tc.matcher)
t.Fatalf("matcher should not match | %+v\n", tc.matcher)
}
}
}()
})
}
}

Expand Down
9 changes: 5 additions & 4 deletions modules/l4socks/socks5_matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package l4socks

import (
"context"
"fmt"
"io"
"net"
"testing"
Expand Down Expand Up @@ -44,7 +45,7 @@ func TestSocks5Matcher_Match(t *testing.T) {
defer cancel()

for i, tc := range tests {
func() {
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
err := tc.matcher.Provision(ctx)
assertNoError(t, err)

Expand All @@ -66,11 +67,11 @@ func TestSocks5Matcher_Match(t *testing.T) {

if matched != tc.shouldMatch {
if tc.shouldMatch {
t.Fatalf("test %d: matcher did not match | %+v\n", i, tc.matcher)
t.Fatalf("matcher did not match | %+v\n", tc.matcher)
} else {
t.Fatalf("test %d: matcher should not match | %+v\n", i, tc.matcher)
t.Fatalf("matcher should not match | %+v\n", tc.matcher)
}
}
}()
})
}
}

0 comments on commit d110e3e

Please sign in to comment.