Skip to content

Commit 07bb01a

Browse files
committed
improve badge name
1 parent 6a3b164 commit 07bb01a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

pkg/testcoverage/badgestorer/github_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package badgestorer_test
22

33
import (
44
"context"
5+
crand "crypto/rand"
6+
"encoding/hex"
57
"fmt"
68
"os"
7-
"runtime"
89
"testing"
9-
"time"
1010

1111
"github.com/google/go-github/v56/github"
1212
"github.com/stretchr/testify/assert"
@@ -56,7 +56,7 @@ func Test_Github(t *testing.T) {
5656
Branch: "badges-integration-test",
5757
// badge name must be unique because two tests running from different platforms
5858
// in CI can cause race condition if badge has the same name
59-
FileName: fmt.Sprintf("badge_%s_%d.svg", runtime.GOOS, time.Now().UnixNano()),
59+
FileName: fmt.Sprintf("badge_%s.svg", randName()),
6060
}
6161
s := NewGithub(cfg)
6262

@@ -110,3 +110,14 @@ func deleteFile(t *testing.T, cfg Git) {
110110
)
111111
assert.NoError(t, err)
112112
}
113+
114+
func randName() string {
115+
buf := make([]byte, 20)
116+
117+
_, err := crand.Read(buf)
118+
if err != nil {
119+
panic(err) //nolint:forbidigo // okay here because it is only used for tests
120+
}
121+
122+
return hex.EncodeToString(buf)
123+
}

0 commit comments

Comments
 (0)