]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/rand: improve TestReadLoops
authorFilippo Valsorda <filippo@golang.org>
Mon, 26 Aug 2024 15:53:46 +0000 (17:53 +0200)
committerFilippo Valsorda <filippo@golang.org>
Mon, 7 Oct 2024 15:34:34 +0000 (15:34 +0000)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/crypto/rand/rand_test.go

index 003a8de9aeee2fb84fae82cf818edbde6c44d7a1..f201cf0ff31fc2cade46196269e86a970c12cc2c 100644 (file)
@@ -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
                }
        }