forked from guanguans/id-validator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathid_validator_test.go
84 lines (75 loc) · 1.58 KB
/
id_validator_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
package idvalidator
import (
"testing"
)
// go test -v -cover -coverprofile=cover.out
// go tool cover -func=cover.out
// go tool cover -html=cover.out
func TestIsValid(t *testing.T) {
ids := [4]string{
"440308199901101512",
"610104620927690",
"810000199408230021",
"830000199201300022",
}
for _, id := range ids {
if !IsValid(id, false) {
t.Errorf("%s must be true.", id)
}
}
errIds := [6]string{
"440308199901101513",
"4403081999011015133",
"510104621927691",
"61010462092769",
"810000199408230022",
"830000199201300023",
}
for _, id := range errIds {
if IsValid(id, true) {
t.Errorf("%s must be false.", id)
}
}
}
func TestGetInfo(t *testing.T) {
_, err := GetInfo("440308199901101512", false)
if err != nil {
t.Errorf("Errors must be nil.")
}
_, e := GetInfo("440308199901101513", true)
if e == nil {
t.Errorf("Errors must not be nil.")
}
}
func TestUpgradeId(t *testing.T) {
_, err := UpgradeId("610104620927690")
if err != nil {
t.Errorf("Errors must be nil.")
}
_, e := UpgradeId("61010462092769")
if e == nil {
t.Errorf("Errors must not be nil.")
}
}
func TestFakeId(t *testing.T) {
id := FakeId()
if len(id) != 18 {
t.Errorf("String length must be 18. : %s", id)
}
if !IsValid(id, false) {
t.Errorf("%s must be true.", id)
}
}
func TestFakeRequireId(t *testing.T) {
id := FakeRequireId(false, "", "", 0)
if len(id) != 15 {
t.Errorf("String length must be 15. : %s", id)
}
if !IsValid(id, false) {
t.Errorf("%s must be true.", id)
}
info, _ := GetInfo(id, false)
if info.Sex != 0 {
t.Errorf("%s must be 0.", "0")
}
}