forked from GetStream/stream-chat-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
43 lines (35 loc) · 1.09 KB
/
utils_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package stream_chat //nolint: golint
import (
"math/rand"
"os"
"time"
)
//nolint: gochecknoglobals
var (
APIKey = os.Getenv("STREAM_CHAT_API_KEY")
APISecret = os.Getenv("STREAM_CHAT_API_SECRET")
StreamHost = os.Getenv("STREAM_CHAT_API_HOST")
serverUser *User
testUsers []*User
)
//nolint: gochecknoinits
func init() {
rand.Seed(time.Now().UnixNano())
serverUser = &User{ID: randomString(10), Name: "Gandalf the Grey", ExtraData: map[string]interface{}{"race": "Istari"}}
testUsers = []*User{
{ID: randomString(10), Name: "Frodo Baggins", ExtraData: map[string]interface{}{"race": "Hobbit", "age": 50}},
{ID: randomString(10), Name: "Samwise Gamgee", ExtraData: map[string]interface{}{"race": "Hobbit", "age": 38}},
{ID: randomString(10), Name: "Legolas", ExtraData: map[string]interface{}{"race": "Elf", "age": 500}},
serverUser,
}
}
func randomUser() *User {
return testUsers[rand.Intn(len(testUsers)-1)]
}
func randomString(n int) string {
bytes := make([]byte, n)
for i := 0; i < n; i++ {
bytes[i] = byte(65 + rand.Intn(25)) // A=65 and Z = 65+25
}
return string(bytes)
}