-
Notifications
You must be signed in to change notification settings - Fork 0
/
pick_test.go
62 lines (52 loc) · 1.46 KB
/
pick_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
56
57
58
59
60
61
62
package main
import (
"math/rand"
"testing"
whoswho "github.com/Clever/who-is-who/go-client"
"github.com/stretchr/testify/assert"
)
// set random source in unit tests, so they run predictably
var source = rand.NewSource(0)
func TestPickUser(t *testing.T) {
assert := assert.New(t)
currentUser := whoswho.User{
SlackID: "U99995",
}
u1 := whoswho.User{SlackID: "U99991"}
u2 := whoswho.User{SlackID: "U99992"}
users := []whoswho.User{currentUser, u1, u2}
omit := ¤tUser
picked, err := pickUser(users, omit, source)
assert.NoError(err)
assert.Equal(u1, picked)
}
func TestPickUserFailsIfEmptyUserList(t *testing.T) {
assert := assert.New(t)
t.Log("Fails if empty list")
users := []whoswho.User{}
_, err := pickUser(users, nil, source)
assert.Error(err)
assert.Equal(ErrNoUsers, err)
t.Log("Fails if empty list due to omitted user")
currentUser := whoswho.User{
SlackID: "U99995",
}
users = []whoswho.User{currentUser}
omit := ¤tUser
_, err = pickUser(users, omit, source)
assert.Error(err)
assert.Equal(ErrNoUsers, err)
}
func TestPickUserDedupsBySlackID(t *testing.T) {
assert := assert.New(t)
currentUser := whoswho.User{
SlackID: "U99995",
}
u1 := whoswho.User{SlackID: "U99991"}
u2 := whoswho.User{SlackID: "U99992"}
users := []whoswho.User{currentUser, currentUser, u1, u2, u2, u2, u2, u2, u2, u2, u2, u2, u2, u2}
omit := ¤tUser
picked, err := pickUser(users, omit, source)
assert.NoError(err)
assert.Equal(u1, picked)
}