-
Notifications
You must be signed in to change notification settings - Fork 0
/
wheel_test.go
49 lines (44 loc) · 1.22 KB
/
wheel_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
package wheel
import (
"reflect"
"testing"
)
func TestGenerate(t *testing.T) {
tk, _ := NewToken("aa")
tk.vendorEpoch = [4]byte{163, 193, 138, 1}
_ = tk.Generate()
if !reflect.DeepEqual(tk.hashToken, []byte{73, 166, 126, 28, 190, 65, 221, 71,
13, 33, 192, 172, 201, 202, 54, 88, 90, 230, 55, 7, 172, 142, 162, 103, 201,
179, 104, 49, 62, 160, 217, 158}) {
t.Errorf("hashToken value mismatch")
}
tk.vendorEpoch = [4]byte{}
if tk.Generate() == nil {
t.Errorf("No error on Generate() with zeroed time")
}
}
func TestGetTokenString(t *testing.T) {
tk, err := NewToken("aa")
if err != nil {
t.Errorf("Error during token creation: %s", err)
}
tk.vendorEpoch = [4]byte{163, 193, 138, 1}
_ = tk.Generate()
tokenString := tk.GetTokenString()
if tokenString != "87492217" {
t.Errorf("token value mismatch (%s vs %s)", "87492217", tokenString)
}
}
func TestNewToken(t *testing.T) {
_, err := NewToken("zz")
if err == nil {
t.Errorf("no error on invalid hexstring")
}
}
func TestSetTime(t *testing.T) {
tk, _ := NewToken("aa")
tk.SetTime(1552308361)
if !reflect.DeepEqual(tk.vendorEpoch, [4]byte{250, 197, 138, 1}) {
t.Errorf("vendorEpoch value mismatch: %v should be %v", tk.vendorEpoch, []byte{250, 197, 138, 1})
}
}