Skip to content

Commit

Permalink
Add RandomUUIDV4 test helper, use UUIDv4 for loadit (sensu#4293)
Browse files Browse the repository at this point in the history
  • Loading branch information
amdprophet authored May 18, 2021
1 parent dcaa8f6 commit cfeddad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion cmd/loadit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions testing/testutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"runtime"
"strings"
"testing"

"github.com/google/uuid"
)

// TempDir provides a test with a temporary directory (under os.TempDir())
Expand Down Expand Up @@ -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
}

0 comments on commit cfeddad

Please sign in to comment.