From 356a222b83222cb018cbc0d6fe93abe2c0502674 Mon Sep 17 00:00:00 2001 From: Achilleas Koutsou Date: Wed, 10 Apr 2024 13:28:58 +0200 Subject: [PATCH] weldr: replace use of deprecated rand.Seed with New(NewSource(seed)) "rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator." --- internal/weldr/api_test.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 84d6c6f49..33b7d1209 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -774,9 +774,10 @@ func TestBlueprintsDelete(t *testing.T) { func TestBlueprintsChanges(t *testing.T) { api, sf := createTestWeldrAPI(t.TempDir(), test_distro.TestDistro1Name, test_distro.TestArchName, rpmmd_mock.BaseFixture, nil) t.Cleanup(sf.Cleanup) - rand.Seed(time.Now().UnixNano()) // math/rand is good enough in this case /* #nosec G404 */ + rand.New(rand.NewSource(time.Now().UnixNano())) + /* #nosec G404 */ id := strconv.Itoa(rand.Int()) ignoreFields := []string{"commit", "timestamp"} @@ -800,9 +801,10 @@ func TestBlueprintsChanges(t *testing.T) { func TestBlueprintChange(t *testing.T) { api, sf := createTestWeldrAPI(t.TempDir(), test_distro.TestDistro1Name, test_distro.TestArchName, rpmmd_mock.BaseFixture, nil) t.Cleanup(sf.Cleanup) - rand.Seed(time.Now().UnixNano()) // math/rand is good enough in this case /* #nosec G404 */ + rand.New(rand.NewSource(time.Now().UnixNano())) + /* #nosec G404 */ id := strconv.Itoa(rand.Int()) test.SendHTTP(api, true, "POST", "/api/v0/blueprints/new", `{"name":"`+id+`","description":"Test","packages":[{"name":"httpd","version":"2.4.*"}],"version":"0.0.1"}`) @@ -860,9 +862,10 @@ func TestBlueprintsDepsolve(t *testing.T) { func TestOldBlueprintsUndo(t *testing.T) { api, sf := createTestWeldrAPI(t.TempDir(), test_distro.TestDistro1Name, test_distro.TestArchName, rpmmd_mock.OldChangesFixture, nil) t.Cleanup(sf.Cleanup) - rand.Seed(time.Now().UnixNano()) // math/rand is good enough in this case /* #nosec G404 */ + rand.New(rand.NewSource(time.Now().UnixNano())) + /* #nosec G404 */ ignoreFields := []string{"commit", "timestamp"} test.TestRoute(t, api, true, "GET", "/api/v0/blueprints/changes/test-old-changes", ``, http.StatusOK, oldBlueprintsUndoResponse, ignoreFields...) @@ -895,9 +898,10 @@ func TestOldBlueprintsUndo(t *testing.T) { func TestNewBlueprintsUndo(t *testing.T) { api, sf := createTestWeldrAPI(t.TempDir(), test_distro.TestDistro1Name, test_distro.TestArchName, rpmmd_mock.BaseFixture, nil) t.Cleanup(sf.Cleanup) - rand.Seed(time.Now().UnixNano()) // math/rand is good enough in this case /* #nosec G404 */ + rand.New(rand.NewSource(time.Now().UnixNano())) + /* #nosec G404 */ id := strconv.Itoa(rand.Int()) ignoreFields := []string{"commit", "timestamp"}