-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
claims_pub_test.go
93 lines (84 loc) · 2.49 KB
/
claims_pub_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package sjwt
import "testing"
func TestClaims(t *testing.T) {
claims := New()
claims.Set("temp", "temp val")
claims.Set("bool", true)
claims.Set("stringbool", "true")
claims.Set("string", "hello world")
claims.Set("intstring", 8675309)
claims.Set("float32string", float32(86753.09))
claims.Set("float64string", float64(86753.09))
claims.Set("int", 8675309)
claims.Set("uintint", uint(8675309))
claims.Set("floatint", 86753.09)
claims.Set("stringint", "8675309")
claims.Set("float", 8675309.69)
claims.Set("stringfloat", "8675309.69")
// Check has function
if !claims.Has("temp") {
t.Error("temp doesnt exist when it should")
}
// Check normal get
temp, _ := claims.Get("temp")
if temp.(string) != "temp val" {
t.Error("getting temp received incorrect value")
}
// Check deletion
claims.Del("temp")
if claims.Has("temp") {
t.Error("temp exists when it should have been recently deleted")
}
// Boolean
bool, _ := claims.GetBool("bool")
if bool != true {
t.Error("bool claim is incorrect, got: ", bool)
}
stringbool, _ := claims.GetBool("stringbool")
if stringbool != true {
t.Error("stringbool claim is incorrect, got: ", stringbool)
}
// String
string, _ := claims.GetStr("string")
if string != "hello world" {
t.Error("string claim is incorrect, got: ", string)
}
intstring, _ := claims.GetStr("intstring")
if intstring != "8675309" {
t.Error("intstring claim is incorrect, got: ", intstring)
}
float32string, _ := claims.GetStr("float32string")
if float32string != "86753.09" {
t.Error("float32string claim is incorrect, got: ", float32string)
}
float64string, _ := claims.GetStr("float64string")
if float64string != "86753.09" {
t.Error("float64string claim is incorrect, got: ", float64string)
}
// Integer
int, _ := claims.GetInt("int")
if int != 8675309 {
t.Error("int claim is incorrect, got: ", int)
}
uintint, _ := claims.GetInt("uintint")
if uintint != 8675309 {
t.Error("uintint claim is incorrect, got: ", uintint)
}
floatint, _ := claims.GetInt("floatint")
if floatint != 86753 {
t.Error("floatint claim is incorrect, got: ", floatint)
}
stringint, _ := claims.GetInt("stringint")
if stringint != 8675309 {
t.Error("stringint claim is incorrect, got: ", stringint)
}
// Float
float, _ := claims.GetFloat("float")
if float != 8675309.69 {
t.Error("float claim is incorrect, got: ", float)
}
stringfloat, _ := claims.GetFloat("stringfloat")
if stringfloat != 8675309.69 {
t.Error("stringfloat claim is incorrect, got: ", stringfloat)
}
}