Skip to content

Instantly share code, notes, and snippets.

@TrinhTrungDung
Created March 20, 2020 12:09
Show Gist options
  • Save TrinhTrungDung/986e0396f435f7cfec62ef1cd9ba2e83 to your computer and use it in GitHub Desktop.
Save TrinhTrungDung/986e0396f435f7cfec62ef1cd9ba2e83 to your computer and use it in GitHub Desktop.
Test file contains helper functions
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