From cfeddadf385d1b8e1f5b6a678ce5cf9991b0115b Mon Sep 17 00:00:00 2001 From: Justin Kolberg Date: Tue, 18 May 2021 12:49:57 -0700 Subject: [PATCH] Add RandomUUIDV4 test helper, use UUIDv4 for loadit (#4293) --- CHANGELOG.md | 2 ++ cmd/loadit/main.go | 6 +++++- testing/testutil/util.go | 12 ++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f3dfe9019..5cd194801a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ embedded etcd server. ### Changed - Upgraded Go version from 1.13.15 to 1.16. - Upgraded Etcd version from 3.3.22 to 3.4.15. +- The loadit tool now uses UUIDv4 instead of UUIDv1 for agent names. + ## Unreleased ### Fixed diff --git a/cmd/loadit/main.go b/cmd/loadit/main.go index 6713081cad..8ffa6a95f4 100644 --- a/cmd/loadit/main.go +++ b/cmd/loadit/main.go @@ -47,7 +47,11 @@ func main() { start := time.Now() for i := 0; i < *flagCount; i++ { - name := uuid.New().String() + uuidBytes, err := uuid.NewRandom() + if err != nil { + log.Fatal(err) + } + name := uuidBytes.String() cfg := agent.NewConfig() cfg.API.Host = agent.DefaultAPIHost diff --git a/testing/testutil/util.go b/testing/testutil/util.go index 47320032d5..e0ebc73318 100644 --- a/testing/testutil/util.go +++ b/testing/testutil/util.go @@ -7,6 +7,8 @@ import ( "runtime" "strings" "testing" + + "github.com/google/uuid" ) // TempDir provides a test with a temporary directory (under os.TempDir()) @@ -44,3 +46,13 @@ func CommandPath(s string, p ...string) string { fullCmd := fmt.Sprintf("%s %s", command, params) return strings.Trim(fullCmd, " ") } + +// RandomUUIDV4 takes a testing.TB and will attempt to generate a random +// Version 4 UUID. If an error is returned, a fatal testing error will occur. +func RandomUUIDV4(tb testing.TB) uuid.UUID { + bytes, err := uuid.NewRandom() + if err != nil { + tb.Fatalf("failed to generate uuid: %s", err) + } + return bytes +}