Skip to content

Commit ccd5438

Browse files
committed
chore: Linting the random package
1 parent 2c8680e commit ccd5438

2 files changed

Lines changed: 18 additions & 8 deletions

File tree

modules/random/random.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ func RandomString(elements []string) string {
2727
const base62chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
2828
const uniqueIDLength = 6 // Should be good for 62^6 = 56+ billion combinations
2929

30-
// UniqueId returns a unique (ish) id we can attach to resources and tfstate files so they don't conflict with each other
30+
// UniqueID returns a unique (ish) id we can attach to resources and tfstate files so they don't conflict with each other
3131
// Uses base 62 to generate a 6 character string that's unlikely to collide with the handful of tests we run in
3232
// parallel. Based on code here: http://stackoverflow.com/a/9543797/483528
33-
func UniqueId() string {
33+
func UniqueID() string {
3434
var out bytes.Buffer
3535

3636
generator := newRand()
@@ -41,6 +41,15 @@ func UniqueId() string {
4141
return out.String()
4242
}
4343

44+
// UniqueId is deprecated, use UniqueID instead.
45+
//
46+
// Deprecated: Use UniqueID.
47+
//
48+
//nolint:staticcheck,revive
49+
func UniqueId() string {
50+
return UniqueID()
51+
}
52+
4453
// newRand creates a new random number generator, seeding it with the current system time.
4554
func newRand() *rand.Rand {
4655
return rand.New(rand.NewSource(time.Now().UnixNano()))

modules/random/random_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
package random
1+
package random_test
22

33
import (
44
"strconv"
55
"testing"
66

7+
"github.com/gruntwork-io/terratest/modules/random"
78
"github.com/stretchr/testify/assert"
89
)
910

@@ -14,7 +15,7 @@ func TestRandom(t *testing.T) {
1415
max := 100
1516

1617
for i := 0; i < 100000; i++ {
17-
value := Random(min, max)
18+
value := random.Random(min, max)
1819
assert.True(t, value >= min && value <= max)
1920
}
2021
}
@@ -31,7 +32,7 @@ func TestRandomInt(t *testing.T) {
3132
}
3233

3334
for i := 0; i < 100000; i++ {
34-
value := RandomInt(list)
35+
value := random.RandomInt(list)
3536
assert.Contains(t, list, value)
3637
}
3738
}
@@ -48,18 +49,18 @@ func TestRandomString(t *testing.T) {
4849
}
4950

5051
for i := 0; i < 100000; i++ {
51-
value := RandomString(list)
52+
value := random.RandomString(list)
5253
assert.Contains(t, list, value)
5354
}
5455
}
5556

56-
func TestUniqueId(t *testing.T) {
57+
func TestUniqueID(t *testing.T) {
5758
t.Parallel()
5859

5960
previouslySeen := map[string]bool{}
6061

6162
for i := 0; i < 100; i++ {
62-
uniqueID := UniqueId()
63+
uniqueID := random.UniqueID()
6364
assert.Len(t, uniqueID, 6)
6465
assert.NotContains(t, previouslySeen, uniqueID)
6566

0 commit comments

Comments
 (0)