-
Notifications
You must be signed in to change notification settings - Fork 3
/
namescache_test.go
55 lines (45 loc) · 1.14 KB
/
namescache_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
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"sync"
"testing"
)
func TestNamescacheRefresh(t *testing.T) {
initEntities()
uid := Userid(1)
u := &User{}
u.id = uid
u.nick = "testnick"
u.setFeatures([]string{"admin", "moderator", "protected", "subscriber", "vip", "bot"})
u.assembleSimplifiedUser()
nc := &namesCache{
users: make(map[Userid]*User),
RWMutex: sync.RWMutex{},
}
nc.add(u)
if nu, ok := nc.users[uid]; ok {
if nu.connections != 1 {
t.Errorf("Usercount was not 1 but %v, %+v", u.connections, u)
}
if len(*nu.simplified.Features) != 6 {
t.Errorf("Simplified user features length was not 6 %+v", nu.simplified.Features)
}
} else {
t.Errorf("Namescache did not have user %+v", nu)
}
u = &User{}
u.id = uid
u.nick = "NEWNICK"
u.setFeatures([]string{"protected"})
u.assembleSimplifiedUser()
nc.refresh(u)
if nu, ok := nc.users[uid]; ok {
if nu.nick != "NEWNICK" {
t.Errorf("Users refresh did not succeed, nick was %+v", nu.nick)
}
if len(*nu.simplified.Features) != 1 {
t.Errorf("Simplified user features length was not 1 %+v", nu.simplified.Features)
}
} else {
t.Errorf("Namescache did not have user %+v", nu)
}
}