From c27f63a5570f068d979001176a2a74e49c9dad31 Mon Sep 17 00:00:00 2001 From: CHIKAMATSU Naohiro Date: Fri, 29 Dec 2023 22:41:20 +0900 Subject: [PATCH] fix: reviewdog review --- app/domain/model/s3.go | 2 +- app/domain/model/s3_test.go | 5 +++++ app/external/s3_retryer.go | 11 ++++++----- cmd/subcmd/common_test.go | 4 +++- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/domain/model/s3.go b/app/domain/model/s3.go index 98cdffb..2ec8bb2 100644 --- a/app/domain/model/s3.go +++ b/app/domain/model/s3.go @@ -310,7 +310,7 @@ func (s S3ObjectSets) Len() int { // ToS3ObjectIdentifiers converts the S3ObjectSets to the ObjectIdentifiers. func (s S3ObjectSets) ToS3ObjectIdentifiers() []types.ObjectIdentifier { - var ids []types.ObjectIdentifier + ids := make([]types.ObjectIdentifier, 0, s.Len()) for _, o := range s { ids = append(ids, *o.ToS3ObjectIdentifier()) } diff --git a/app/domain/model/s3_test.go b/app/domain/model/s3_test.go index 14bc045..1207d32 100644 --- a/app/domain/model/s3_test.go +++ b/app/domain/model/s3_test.go @@ -4,6 +4,7 @@ package model import ( "errors" "path/filepath" + "runtime" "strings" "testing" ) @@ -599,6 +600,10 @@ func TestBucket_TrimKey(t *testing.T) { } func TestBucket_Split(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Skip this test on Windows") + } + t.Parallel() tests := []struct { diff --git a/app/external/s3_retryer.go b/app/external/s3_retryer.go index 14a12bb..2b9b842 100644 --- a/app/external/s3_retryer.go +++ b/app/external/s3_retryer.go @@ -2,7 +2,8 @@ package external import ( "context" - "math/rand" + "crypto/rand" + "math/big" "time" "github.com/aws/aws-sdk-go-v2/aws" @@ -39,11 +40,11 @@ func (r *Retryer) MaxAttempts() int { // RetryDelay returns the delay time. func (r *Retryer) RetryDelay(int, error) (time.Duration, error) { - rand.NewSource(time.Now().UnixNano()) - waitTime := 1 - if r.delayTimeSec > 1 { - waitTime += rand.Intn(r.delayTimeSec) + randomInt, err := rand.Int(rand.Reader, big.NewInt(int64(r.delayTimeSec))) + if err != nil { + return 0, err } + waitTime := 1 + int(randomInt.Int64()) return time.Duration(waitTime) * time.Second, nil } diff --git a/cmd/subcmd/common_test.go b/cmd/subcmd/common_test.go index bd3f49f..0f2c4d7 100644 --- a/cmd/subcmd/common_test.go +++ b/cmd/subcmd/common_test.go @@ -118,6 +118,8 @@ func mockStdin(t *testing.T, dummyInput string) (funcDefer func(), err error) { return func() { // clean up os.Stdin = oldOsStdin - os.Remove(tmpFile.Name()) + if err := os.Remove(tmpFile.Name()); err != nil { + t.Error(err) + } }, nil }