From: Filippo Valsorda Date: Mon, 26 Aug 2024 15:53:46 +0000 (+0200) Subject: crypto/rand: improve TestReadLoops X-Git-Tag: go1.24rc1~741 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=55b930eb07ab353ade10756dc9a4f7951e93e211;p=gostls13.git crypto/rand: improve TestReadLoops As suggested by Russ Cox, making sure we see all byte values doesn't take long and is a superset of the existing test. Change-Id: Ifc7f18ca4189c89a3d06d0408150a2464ce5e590 Reviewed-on: https://go-review.googlesource.com/c/go/+/608397 LUCI-TryBot-Result: Go LUCI Reviewed-by: Roland Shoemaker Reviewed-by: Daniel McCarney Reviewed-by: Michael Knyszek --- diff --git a/src/crypto/rand/rand_test.go b/src/crypto/rand/rand_test.go index 003a8de9ae..f201cf0ff3 100644 --- a/src/crypto/rand/rand_test.go +++ b/src/crypto/rand/rand_test.go @@ -49,27 +49,20 @@ func testRead(t *testing.T, Read func([]byte) (int, error)) { } } -func TestReadLoops(t *testing.T) { - testReadAndReader(t, testReadLoops) +func TestReadByteValues(t *testing.T) { + testReadAndReader(t, testReadByteValues) } -func testReadLoops(t *testing.T, Read func([]byte) (int, error)) { +func testReadByteValues(t *testing.T, Read func([]byte) (int, error)) { b := make([]byte, 1) + v := make(map[byte]bool) for { n, err := Read(b) if n != 1 || err != nil { t.Fatalf("Read(b) = %d, %v", n, err) } - if b[0] == 42 { - break - } - } - for { - n, err := Read(b) - if n != 1 || err != nil { - t.Fatalf("Read(b) = %d, %v", n, err) - } - if b[0] == 0 { + v[b[0]] = true + if len(v) == 256 { break } }