forked from bxcodec/faker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internet_test.go
168 lines (154 loc) · 3.55 KB
/
internet_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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package faker
import (
"reflect"
"regexp"
"strings"
"testing"
"github.com/bxcodec/faker/v3/support/slice"
)
func TestEmail(t *testing.T) {
email, err := GetNetworker().Email(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if !strings.Contains(email.(string), "@") {
t.Error("Expected email")
}
}
func TestMacAddress(t *testing.T) {
i := Internet{}
mc, err := i.MacAddress(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if strings.Count(mc.(string), ":") != 5 {
t.Error("Expected mac address")
}
}
func TestDomainName(t *testing.T) {
domain, err := GetNetworker().DomainName(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
preTld := strings.Split(domain.(string), ".")
if !slice.Contains(tld, preTld[1]) {
t.Error("Expected get DomainName")
}
}
func TestURLOneVerbs(t *testing.T) {
urlFormats = []string{
"http://www.%s/"}
res, err := GetNetworker().URL(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if !strings.Contains(res.(string), "http") {
t.Error("Expected get url")
}
}
func TestURLTwoVerbs(t *testing.T) {
urlFormats = []string{
"http://www.%s/%s"}
res, err := GetNetworker().URL(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if !strings.Contains(res.(string), "http") {
t.Error("Expected get url")
}
}
func TestUserName(t *testing.T) {
usrname, err := GetNetworker().UserName(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if usrname.(string) == "" {
t.Error("Expected get username")
}
}
func TestIPv4(t *testing.T) {
ip, err := GetNetworker().IPv4(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if strings.Count(ip.(string), ".") != 3 {
t.Error("Expected IPv4 format")
}
}
func TestIPv6(t *testing.T) {
ip, err := GetNetworker().IPv6(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if strings.Count(ip.(string), ":") != 7 {
t.Error("Expected IPv4 format")
}
}
func TestSetNetwork(t *testing.T) {
SetNetwork(Internet{})
}
func TestPassword(t *testing.T) {
pass, err := GetNetworker().Password(reflect.Value{})
if err != nil {
t.Error("Expected not error, got err", err)
}
if pass.(string) == "" {
t.Error("Expected hash password")
}
}
func TestFakeEmail(t *testing.T) {
email := Email()
if !strings.Contains(email, "@") {
t.Error("Expected email")
}
}
func TestFakeMacAddress(t *testing.T) {
mc := MacAddress()
if strings.Count(mc, ":") != 5 {
t.Error("Expected mac address")
}
}
func TestFakeDomainName(t *testing.T) {
domain := DomainName()
preTld := strings.Split(domain, ".")
if !slice.Contains(tld, preTld[1]) {
t.Error("Expected get DomainName")
}
}
func TestFakeURL(t *testing.T) {
resURL := URL()
if !strings.Contains(resURL, "http") {
t.Error("Expected get url")
}
}
func TestFakeUserName(t *testing.T) {
usrname := Username()
if usrname == "" {
t.Error("Expected get username")
}
}
func TestFakeIPv4(t *testing.T) {
ip := IPv4()
if strings.Count(ip, ".") != 3 {
t.Error("Expected IPv4 format")
}
}
func TestFakeIPv6(t *testing.T) {
ip := IPv6()
if strings.Count(ip, ":") != 7 {
t.Error("Expected IPv4 format")
}
}
func TestFakePassword(t *testing.T) {
pass := Password()
if pass == "" {
t.Error("Expected hash password")
}
}
func TestFakeJWT(t *testing.T) {
jwt := Jwt()
reg := regexp.MustCompile(`[a-zA-Z]+.[a-zA-Z]+.[a-zA-Z]+`)
if !reg.MatchString(jwt) {
t.Error("Invalid format on JWT token")
}
}