-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
46 lines (44 loc) · 794 Bytes
/
client_test.go
File metadata and controls
46 lines (44 loc) · 794 Bytes
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
package wexapi
import (
"math"
"testing"
)
func TestClient_nonce(t *testing.T) {
tests := []struct {
name string
nonce uint32
want string
wantErr bool
}{
{
name: "normal flow",
want: "1",
wantErr: false,
nonce: 1,
},
{
name: "overflow",
want: "",
wantErr: true,
nonce: uint32(math.MaxUint32) - 1,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cli := Client{
noncePool: make(chan uint32),
}
go func() {
cli.noncePool <- tt.nonce
}()
got, err := cli.nonce()
if (err != nil) != tt.wantErr {
t.Errorf("Client.nonce() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("Client.nonce() = %v, want %v", got, tt.want)
}
})
}
}