Skip to content

Commit

Permalink
add unittest for RandString
Browse files Browse the repository at this point in the history
Signed-off-by: yxxhero <[email protected]>
  • Loading branch information
yxxhero authored and gaius-qi committed Aug 31, 2021
1 parent 41af67f commit cdda432
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/util/stringutils/string_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Contains(slice []string, ele string) bool {
}

func RandString(len int) string {
r := rand.New(rand.NewSource(time.Now().Unix()))
r := rand.New(rand.NewSource(time.Now().UnixNano()))
bytes := make([]byte, len)
for i := 0; i < len; i++ {
b := r.Intn(26) + 65
Expand Down
7 changes: 7 additions & 0 deletions pkg/util/stringutils/string_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,10 @@ func TestContains(t *testing.T) {
assert.True(t, ContainsFold([]string{"a", "B"}, "b"))
assert.False(t, Contains([]string{"a", "B"}, "b"))
}

func TestRandString(t *testing.T) {
assert.True(t, len(RandString(10)) == 10)
x := RandString(10)
y := RandString(10)
assert.False(t, x == y)
}

0 comments on commit cdda432

Please sign in to comment.