-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
80 lines (72 loc) · 1.83 KB
/
main_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
package go_mobilus_sso
import (
"testing"
)
var (
secret = "qwertyuiop"
)
func TestNew(t *testing.T) {
s := New(secret)
if s.Secret != secret {
t.Fatal("invalid secret")
}
}
var last string
func TestMobilusSSO_Marshal(t *testing.T) {
s := New(secret)
t.Run("valid", func(t1 *testing.T) {
c, err := s.Marshal(User{
Name: "テストマン",
PermitLevel: 0,
Token: "thisistesttoken",
DomainID: "adm",
PlusID: "[email protected]",
UserID: "[email protected]",
TenantID: "mobilus",
})
if err != nil {
t1.Fatal("marshal error", err)
}
if c == "" {
t1.Fatal("marshal error", "empty string")
}
last = c
})
t.Run("invalid", func(t1 *testing.T) {
_, err := s.Marshal(func() {})
if err == nil {
t1.Fatal("marshal error", err)
}
})
}
func TestMobilusSSO_Unmarshal(t *testing.T) {
s := New(secret)
t.Run("valid", func(t1 *testing.T) {
user, err := s.Unmarshal(last)
if err != nil {
t1.Fatal("unmarshal error", err)
}
switch {
case user.Name != "テストマン":
t1.Fatal("unmarshal error", "invalid name", user.Name)
case user.PermitLevel != 0:
t1.Fatal("unmarshal error", "invalid permitLevel", user.PermitLevel)
case user.Token != "thisistesttoken":
t1.Fatal("unmarshal error", "invalid token", user.Token)
case user.DomainID != "adm":
t1.Fatal("unmarshal error", "invalid domainId", user.DomainID)
case user.PlusID != "[email protected]":
t1.Fatal("unmarshal error", "invalid plusId", user.PlusID)
case user.UserID != "[email protected]":
t1.Fatal("unmarshal error", "invalid userId", user.UserID)
case user.TenantID != "mobilus":
t1.Fatal("unmarshal error", "invalid tenantId", user.TenantID)
}
})
t.Run("invalid", func(t1 *testing.T) {
_, err := s.Unmarshal("")
if err == nil {
t1.Fatal("marshal error", err)
}
})
}