MCPcopy Create free account
hub / github.com/coder/coder / TestRandError_pre_Go1_24

Function TestRandError_pre_Go1_24

cryptorand/errors_go123_test.go:22–35  ·  view source on GitHub ↗

TestRandError_pre_Go1_24 checks that the code handles errors when reading from the rand.Reader. This test replaces the global rand.Reader, so cannot be parallelized nolint:paralleltest

(t *testing.T)

Source from the content-addressed store, hash-verified

20//
21//nolint:paralleltest
22func TestRandError_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}

Callers

nothing calls this directly

Calls 3

HexStringFunction · 0.92
CleanupMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected