Skip to content

Commit

Permalink
internal/e2e: make unique module names more robust
Browse files Browse the repository at this point in the history
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í <mvdan@mvdan.cc>
Change-Id: Ib4c06a26df908376426677bc7606f99a54f012ee
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1172000
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan committed Nov 10, 2023
1 parent 67ea9cf commit a404c89
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0-rc4
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.5
github.com/tetratelabs/wazero v1.0.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsK
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4=
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc h1:mutztH6OmvFf2MGH0cqacv/FCFLkJn/rz3i7E/VWfm0=
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c h1:fPpdjePK1atuOg28PXfNSqgwf9I/qD1Hlo39JFwKBXk=
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
Expand Down
2 changes: 1 addition & 1 deletion internal/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
cuelang.org/go v0.0.0-00010101000000-000000000000
github.com/google/go-github/v56 v56.0.0
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c
github.com/rogpeppe/retry v0.1.0
)

Expand Down
4 changes: 2 additions & 2 deletions internal/e2e/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ github.com/opencontainers/image-spec v1.1.0-rc4 h1:oOxKUJWnFC4YGHCCMNql1x4YaDfYB
github.com/opencontainers/image-spec v1.1.0-rc4/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4=
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc h1:mutztH6OmvFf2MGH0cqacv/FCFLkJn/rz3i7E/VWfm0=
github.com/rogpeppe/go-internal v1.11.1-0.20230926105539-32ae33786ecc/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c h1:fPpdjePK1atuOg28PXfNSqgwf9I/qD1Hlo39JFwKBXk=
github.com/rogpeppe/go-internal v1.11.1-0.20231026093722-fa6a31e0812c/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/rogpeppe/retry v0.1.0 h1:6km4oqeZcFrnhx+PCPg/YxV3fnTdROBNVlSl8Pe/ztU=
github.com/rogpeppe/retry v0.1.0/go.mod h1:/PtRtl9qXn+Pv5S4wN+Y5nusihQeI1PJ9U7KDcKzuvI=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
Expand Down
19 changes: 13 additions & 6 deletions internal/e2e/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package e2e_test
import (
"bytes"
"context"
cryptorand "crypto/rand"
"fmt"
"net/http"
"os"
Expand Down Expand Up @@ -252,11 +253,17 @@ func tsExpand(ts *testscript.TestScript, s string) string {
}

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

0 comments on commit a404c89

Please sign in to comment.