Skip to content

Commit a404c89

Browse files
committed
internal/e2e: make unique module names more robust
The names used to be a timestamp to the nearest second: > create-github-repo created github repo: https://github.com/cue-labs-modules-testing/2023-11-10.13-32-37 This caused issues in CI already, since we already have two github tests which both create a repository with such a name under the same org, and it's likely that they will both start around the same time: > create-github-repo private=true FAIL: [...]: 422 Repository creation failed [...] name already exists on this account Make clashes between different tests impossible by adding their name as a prefix, via the TestScript.Name method we recently added. Since clashes between different "go test" runs of the same test around the same time are still possible, we also add a random suffix. Now, the names are longer, but far less likely to conflict: > create-github-repo created github repo: https://github.com/cue-labs-modules-testing/e2e-github_app_public-2023.11.10-13.33.05-b369bc Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ib4c06a26df908376426677bc7606f99a54f012ee Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1172000 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]>
1 parent 67ea9cf commit a404c89

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/opencontainers/go-digest v1.0.0
1616
github.com/opencontainers/image-spec v1.1.0-rc4
1717
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0
18-
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc
18+
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c
1919
github.com/spf13/cobra v1.7.0
2020
github.com/spf13/pflag v1.0.5
2121
github.com/tetratelabs/wazero v1.0.2

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
3434
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4=
3535
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
3636
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
37-
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc h1:mutztH6OmvFf2MGH0cqacv/FCFLkJn/rz3i7E/VWfm0=
38-
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
37+
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c h1:fPpdjePK1atuOg28PXfNSqgwf9I/qD1Hlo39JFwKBXk=
38+
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
3939
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
4040
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
4141
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=

internal/e2e/go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.20
55
require (
66
cuelang.org/go v0.0.0-00010101000000-000000000000
77
github.com/google/go-github/v56 v56.0.0
8-
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc
8+
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c
99
github.com/rogpeppe/retry v0.1.0
1010
)
1111

internal/e2e/go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYB
3232
github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
3333
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4=
3434
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
35-
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc h1:mutztH6OmvFf2MGH0cqacv/FCFLkJn/rz3i7E/VWfm0=
36-
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
35+
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c h1:fPpdjePK1atuOg28PXfNSqgwf9I/qD1Hlo39JFwKBXk=
36+
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
3737
github.com/rogpeppe/retry v0.1.0 h1:6km4oqeZcFrnhx+PCPg/YxV3fnTdROBNVlSl8Pe/ztU=
3838
github.com/rogpeppe/retry v0.1.0/go.mod h1:/PtRtl9qXn+Pv5S4wN+Y5nusihQeI1PJ9U7KDcKzuvI=
3939
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=

internal/e2e/script_test.go

+13-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package e2e_test
1717
import (
1818
"bytes"
1919
"context"
20+
cryptorand "crypto/rand"
2021
"fmt"
2122
"net/http"
2223
"os"
@@ -252,11 +253,17 @@ func tsExpand(ts *testscript.TestScript, s string) string {
252253
}
253254

254255
// testModuleName creates a unique string without any slashes
255-
// which can be used as the base name for a module path to publish,
256-
// so that test runs don't conflict with one another
257-
// and can be easily attributed to a point in time.
256+
// which can be used as the base name for a module path to publish.
257+
//
258+
// It has three components:
259+
// "e2e" with the test name as a prefix, to spot which test created it,
260+
// a timestamp in seconds, to get an idea of when the test was run,
261+
// and a short random suffix to avoid timing collisions between machines.
258262
func testModuleName(ts *testscript.TestScript) string {
259-
// TODO: name the repo after ts.Name once the API lands
260-
// TODO: add a short random suffix to prevent time collisions
261-
return time.Now().UTC().Format("2006-01-02.15-04-05")
263+
var randomTrailer [3]byte
264+
if _, err := cryptorand.Read(randomTrailer[:]); err != nil {
265+
panic(err) // should typically not happen
266+
}
267+
return fmt.Sprintf("e2e-%s-%s-%x", ts.Name(),
268+
time.Now().UTC().Format("2006.01.02-15.04.05"), randomTrailer)
262269
}

0 commit comments

Comments
 (0)