Remove deprecated rand functions in tests

With requirement for golang 1.20 the deprecated rand functions
can be dropped. Do not have to call seed.
This commit is contained in:
2023-10-06 16:34:53 -05:00
parent 6a8d3d1c0b
commit 52e8a8280e

View File

@@ -176,8 +176,6 @@ func assertRestoreFailures(t *testing.T, failedFiles int, expectedFailedFiles in
} }
func TestBackupManager(t *testing.T) { func TestBackupManager(t *testing.T) {
rand.Seed(time.Now().UnixNano())
setTestingT(t) setTestingT(t)
SetLoggingLevel(INFO) SetLoggingLevel(INFO)
@@ -422,7 +420,7 @@ func TestBackupManager(t *testing.T) {
// Create file with random file with certain seed // Create file with random file with certain seed
func createRandomFileSeeded(path string, maxSize int, seed int64) { func createRandomFileSeeded(path string, maxSize int, seed int64) {
rand.Seed(seed) r := rand.New(rand.NewSource(seed))
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil { if err != nil {
LOG_ERROR("RANDOM_FILE", "Can't open %s for writing: %v", path, err) LOG_ERROR("RANDOM_FILE", "Can't open %s for writing: %v", path, err)
@@ -439,7 +437,7 @@ func createRandomFileSeeded(path string, maxSize int, seed int64) {
if bytes > cap(buffer) { if bytes > cap(buffer) {
bytes = cap(buffer) bytes = cap(buffer)
} }
rand.Read(buffer[:bytes]) r.Read(buffer[:bytes])
bytes, err = file.Write(buffer[:bytes]) bytes, err = file.Write(buffer[:bytes])
if err != nil { if err != nil {
LOG_ERROR("RANDOM_FILE", "Failed to write to %s: %v", path, err) LOG_ERROR("RANDOM_FILE", "Failed to write to %s: %v", path, err)
@@ -450,7 +448,7 @@ func createRandomFileSeeded(path string, maxSize int, seed int64) {
} }
func corruptFile(path string, start int, length int, seed int64) { func corruptFile(path string, start int, length int, seed int64) {
rand.Seed(seed) r := rand.New(rand.NewSource(seed))
file, err := os.OpenFile(path, os.O_WRONLY, 0644) file, err := os.OpenFile(path, os.O_WRONLY, 0644)
if err != nil { if err != nil {
@@ -471,7 +469,7 @@ func corruptFile(path string, start int, length int, seed int64) {
} }
buffer := make([]byte, length) buffer := make([]byte, length)
rand.Read(buffer) r.Read(buffer)
_, err = file.Write(buffer) _, err = file.Write(buffer)
if err != nil { if err != nil {