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

Commitc429e0d

Browse files
authored
test(cryptorand): re-enable number error tests (#16956)
Realized it was only the `StringCharset` test that lead to panic, thenumber tests bypass it by reading via the `binary` package.
1 parente6983d8 commitc429e0d

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

‎cryptorand/errors_go123_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//go:build !go1.24
2+
3+
package cryptorand_test
4+
5+
import (
6+
"crypto/rand"
7+
"io"
8+
"testing"
9+
"testing/iotest"
10+
11+
"github.com/stretchr/testify/require"
12+
13+
"github.com/coder/coder/v2/cryptorand"
14+
)
15+
16+
// TestRandError_pre_Go1_24 checks that the code handles errors when
17+
// reading from the rand.Reader.
18+
//
19+
// This test replaces the global rand.Reader, so cannot be parallelized
20+
//
21+
//nolint:paralleltest
22+
funcTestRandError_pre_Go1_24(t*testing.T) {
23+
origReader:=rand.Reader
24+
t.Cleanup(func() {
25+
rand.Reader=origReader
26+
})
27+
28+
rand.Reader=iotest.ErrReader(io.ErrShortBuffer)
29+
30+
// Testing `rand.Reader.Read` for errors will panic in Go 1.24 and later.
31+
t.Run("StringCharset",func(t*testing.T) {
32+
_,err:=cryptorand.HexString(10)
33+
require.ErrorIs(t,err,io.ErrShortBuffer,"expected HexString error")
34+
})
35+
}

‎cryptorand/errors_test.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
//go:build !go1.24
2-
3-
// Testing `rand.Reader.Read` for errors will panic in Go 1.24 and later.
4-
51
package cryptorand_test
62

73
import (
@@ -49,8 +45,5 @@ func TestRandError(t *testing.T) {
4945
require.ErrorIs(t,err,io.ErrShortBuffer,"expected Float64 error")
5046
})
5147

52-
t.Run("StringCharset",func(t*testing.T) {
53-
_,err:=cryptorand.HexString(10)
54-
require.ErrorIs(t,err,io.ErrShortBuffer,"expected HexString error")
55-
})
48+
// See errors_go123_test.go for the StringCharset test.
5649
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp