Created
March 20, 2020 12:09
-
-
Save TrinhTrungDung/986e0396f435f7cfec62ef1cd9ba2e83 to your computer and use it in GitHub Desktop.
Test file contains helper functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"math/rand" | |
"testing" | |
) | |
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
func genRandomString(length int) string { | |
b := make([]byte, length) | |
for i := range b { | |
b[i] = letters[rand.Intn(len(letters))] | |
} | |
return string(b) | |
} | |
func stubUsers(b *testing.B) (users []*User) { | |
for i := 0; i < b.N; i++ { | |
user := &User{ | |
Name: genRandomString(100), | |
Password: genRandomString(100), | |
} | |
users = append(users, user) | |
} | |
return users | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment