mirror of
https://github.com/distribution/distribution.git
synced 2025-09-20 02:34:27 +00:00
Handle rand deprecations in go 1.20
Signed-off-by: James Hewitt <james.hewitt@uk.ibm.com>
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
@@ -221,7 +220,6 @@ func TestRouterWithBadCharacters(t *testing.T) {
|
||||
// with random UTF8 characters not in the 128 bit ASCII range.
|
||||
// These are not valid characters for the router and we expect
|
||||
// 404s on every test.
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
tests := make([]routeTestCase, 1000)
|
||||
for idx := range tests {
|
||||
tests[idx] = routeTestCase{
|
||||
|
@@ -21,6 +21,7 @@ import (
|
||||
)
|
||||
|
||||
var sbsMu sync.Mutex
|
||||
var randSource rand.Rand
|
||||
|
||||
type statsBlobStore struct {
|
||||
stats map[string]int
|
||||
@@ -189,13 +190,13 @@ func makeTestEnv(t *testing.T, name string) *testEnv {
|
||||
func makeBlob(size int) []byte {
|
||||
blob := make([]byte, size)
|
||||
for i := 0; i < size; i++ {
|
||||
blob[i] = byte('A' + rand.Int()%48)
|
||||
blob[i] = byte('A' + randSource.Int()%48)
|
||||
}
|
||||
return blob
|
||||
}
|
||||
|
||||
func init() {
|
||||
rand.Seed(42)
|
||||
randSource = *rand.New(rand.NewSource(42))
|
||||
}
|
||||
|
||||
func populate(t *testing.T, te *testEnv, blobCount, size, numUnique int) {
|
||||
|
@@ -2,9 +2,9 @@ package s3
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/rand"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
|
@@ -3,6 +3,7 @@ package testsuites
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
crand "crypto/rand"
|
||||
"crypto/sha256"
|
||||
"io"
|
||||
"math/rand"
|
||||
@@ -1232,7 +1233,7 @@ func randomFilename(length int64) string {
|
||||
var randomBytes = make([]byte, 128<<20)
|
||||
|
||||
func init() {
|
||||
_, _ = rand.Read(randomBytes) // always returns len(randomBytes) and nil error
|
||||
_, _ = crand.Read(randomBytes) // always returns len(randomBytes) and nil error
|
||||
}
|
||||
|
||||
func randomContents(length int64) []byte {
|
||||
|
@@ -2,6 +2,7 @@ package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
crand "crypto/rand"
|
||||
"io"
|
||||
mrand "math/rand"
|
||||
"testing"
|
||||
@@ -14,7 +15,7 @@ import (
|
||||
func TestSimpleRead(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
content := make([]byte, 1<<20)
|
||||
n, err := mrand.Read(content)
|
||||
n, err := crand.Read(content)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error building random data: %v", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user