Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

test(testutil): improve chan.go error visibility#18406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 1 commit intomainfrommafredri/fix-testutil-errors
Jun 17, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletionstestutil/chan.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,9 @@ package testutil
import (
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// TryReceive will attempt to receive a value from the chan and return it. If
Expand All@@ -14,7 +17,7 @@ func TryReceive[A any](ctx context.Context, t testing.TB, c <-chan A) A {
t.Helper()
select {
case <-ctx.Done():
t.Fatal("timeout")
require.Fail(t, "TryReceive: context expired")
var a A
return a
case a := <-c:
Expand All@@ -31,12 +34,12 @@ func RequireReceive[A any](ctx context.Context, t testing.TB, c <-chan A) A {
t.Helper()
select {
case <-ctx.Done():
t.Fatal("timeout")
require.Fail(t, "RequireReceive: context expired")
var a A
return a
case a, ok := <-c:
if !ok {
t.Fatal("channel closed")
require.Fail(t, "RequireReceive:channel closed")
}
return a
}
Expand All@@ -50,7 +53,7 @@ func RequireSend[A any](ctx context.Context, t testing.TB, c chan<- A, a A) {
t.Helper()
select {
case <-ctx.Done():
t.Fatal("timeout")
require.Fail(t, "RequireSend: context expired")
case c <- a:
// OK!
}
Expand All@@ -68,7 +71,7 @@ func SoftTryReceive[A any](ctx context.Context, t testing.TB, c <-chan A) (A, bo
t.Helper()
select {
case <-ctx.Done():
t.Error("timeout")
assert.Fail(t, "SoftTryReceive: context expired")
var a A
return a, false
case a := <-c:
Expand All@@ -86,12 +89,12 @@ func AssertReceive[A any](ctx context.Context, t testing.TB, c <-chan A) (A, boo
t.Helper()
select {
case <-ctx.Done():
t.Error("timeout")
assert.Fail(t, "AssertReceive: context expired")
var a A
return a, false
case a, ok := <-c:
if !ok {
t.Error("channel closed")
assert.Fail(t, "AssertReceive:channel closed")
}
return a, ok
}
Expand All@@ -107,7 +110,7 @@ func AssertSend[A any](ctx context.Context, t testing.TB, c chan<- A, a A) bool
t.Helper()
select {
case <-ctx.Done():
t.Error("timeout")
assert.Fail(t, "AssertSend: context expired")
return false
case c <- a:
return true
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp