-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_validator_test.go
68 lines (57 loc) · 2.2 KB
/
url_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
package validators
import (
"testing"
)
func TestUrl(t *testing.T) {
/// - Successes
err, abortValidation = Url()("https://example.com")
if err != nil || abortValidation {
t.Errorf(setError("Url()(\"https://example.com\") == %v, %t; expected: \"[error message]\", false"))
}
// Test 1
err, abortValidation = Url(errCustomMessage)("https://example.com")
if err != nil || abortValidation {
t.Errorf(setError("Url(\"error\")(\"https://example.com\") == %v, %t; expected: \"error\", false"))
}
// Test 2
err, abortValidation = Url()("http://127.0.0.1:8080")
if err != nil || abortValidation {
t.Errorf(setError("Url()(\"http://127.0.0.1:8080\") == %v, %t; expected: nil, false"))
}
// Test 3
err, abortValidation = Url(errCustomMessage)("http://127.0.0.1:8080")
if err != nil || abortValidation {
t.Errorf(setError("Url(\"error\")(\"http://127.0.0.1:8080\") == %v, %t; expected: nil, false"))
}
// Test 4
err, abortValidation = Url()("http://localhost:8080")
if err != nil || abortValidation {
t.Errorf(setError("Url()(\"http://localhost:8080\") == %v, %t; expected: nil, false"))
}
// Test 5
err, abortValidation = Url(errCustomMessage)("http://localhost:8080")
if err != nil || abortValidation {
t.Errorf(setError("Url(\"error\")(\"http://localhost:8080\") == %v, %t; expected: nil, false"))
}
// Test 6
err, abortValidation = Url()("ftp://ftp.example.com/file.txt")
if err != nil || abortValidation {
t.Errorf(setError("Url()(\"ftp://ftp.example.com/file.txt\") == %v, %t; expected: nil, false"))
}
// Test 7
err, abortValidation = Url(errCustomMessage)("ftp://ftp.example.com/file.txt")
if err != nil || abortValidation {
t.Errorf(setError("Url(\"error\")(\"ftp://ftp.example.com/file.txt\") == %v, %t; expected: nil, false"))
}
/// - Errors
// Test 1
err, abortValidation = Url()("www.example.com")
if err == nil || abortValidation {
t.Errorf(setError("Url()(\"www.example.com\") == %v, %t; expected: \"[error message]\", false"))
}
// Test 2
err, abortValidation = Url(errCustomMessage)("www.example.com")
if err == nil || err.Error() != errCustom.Error() || abortValidation {
t.Errorf(setError("Url(\"error\")(\"www.example.com\") == %v, %t; expected: \"error\", false"))
}
}