MCPcopy Index your code
hub / github.com/coder/coder / TestRandError

Function TestRandError

cryptorand/errors_test.go:20–49  ·  view source on GitHub ↗

TestRandError 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

18//
19//nolint:paralleltest
20func TestRandError(t *testing.T) {
21 origReader := rand.Reader
22 t.Cleanup(func() {
23 rand.Reader = origReader
24 })
25
26 rand.Reader = iotest.ErrReader(io.ErrShortBuffer)
27
28 t.Run("Int63", func(t *testing.T) {
29 _, err := cryptorand.Int63()
30 require.ErrorIs(t, err, io.ErrShortBuffer, "expected Int63 error")
31 })
32
33 t.Run("Intn_32bit", func(t *testing.T) {
34 _, err := cryptorand.Intn(100)
35 require.ErrorIs(t, err, io.ErrShortBuffer, "expected Intn error")
36 })
37
38 t.Run("Intn_64bit", func(t *testing.T) {
39 _, err := cryptorand.Intn(int(1 << 35))
40 require.ErrorIs(t, err, io.ErrShortBuffer, "expected Intn error")
41 })
42
43 t.Run("Float64", func(t *testing.T) {
44 _, err := cryptorand.Float64()
45 require.ErrorIs(t, err, io.ErrShortBuffer, "expected Float64 error")
46 })
47
48 // See errors_go123_test.go for the StringCharset test.
49}

Callers

nothing calls this directly

Calls 5

Int63Function · 0.92
IntnFunction · 0.92
Float64Function · 0.92
CleanupMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected