-
Notifications
You must be signed in to change notification settings - Fork 1
/
referer_test.go
90 lines (72 loc) · 2.44 KB
/
referer_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
package main
import (
"testing"
)
func TestRefererParser1(t *testing.T) {
refererParser := newRefererParser()
data1 := refererParser.parse(getURL("https://www.google.com"), getURL("https://www.google.com"))
if data1.RefExternalHost != "" {
t.Errorf("invalid data")
}
if data1.RefType == refererTypeSearchEngine {
t.Errorf("invalid data")
}
data2 := refererParser.parse(getURL("http://www.example.com/page.html"), getURL("https://www.google.com"))
if data2.RefExternalHost != "www.google.com" {
t.Errorf("invalid data")
}
}
func TestRefererParser2(t *testing.T) {
refererParser := newRefererParser()
data := refererParser.parse(getURL("https://www.google.com"), getURL("android-app://com.google.android.gm/"))
if data.RefExternalHost == "" {
t.Errorf("invalid data")
}
if data.RefType != refererTypeMailProvider {
t.Errorf("invalid data")
}
}
func TestRefererParser3(t *testing.T) {
refererParser := newRefererParser()
data := refererParser.parse(getURL("1"), getURL("2"))
if data.RefExternalHost != "" {
t.Errorf("invalid data")
}
}
func TestRefererParser4(t *testing.T) {
refererParser := newRefererParser()
data := refererParser.parse(getURL("\x18"), getURL("https://www.google.com"))
if data.RefExternalHost != "" {
t.Errorf("invalid data")
}
}
func TestRefererParser5(t *testing.T) {
refererParser := newRefererParser()
data := refererParser.parse(getURL("https://www.google.com"), getURL("\x18"))
if data.RefExternalHost != "" {
t.Errorf("invalid data")
}
}
func TestRefererParser6(t *testing.T) {
refererParser := newRefererParser()
data1 := refererParser.parse(getURL("https://www.example.com/path/foo/bar"), getURL("https://www.search-engine.com/path/foo/bar"))
if data1.RefExternalHost == "" || data1.RefExternalDomain == "" {
t.Errorf("invalid data")
}
data2 := refererParser.parse(getURL("https://www.example.com/path/foo/bar"), getURL("https://another-sub.example.com/path/foo/bar"))
if data2.RefExternalHost == "" || data2.RefExternalDomain != "" {
t.Errorf("invalid data")
}
data3 := refererParser.parse(getURL("https://www.example.com/path/foo/bar"), getURL("https://www.example.com"))
if data3.RefExternalHost != "" || data3.RefExternalDomain != "" {
t.Errorf("invalid data")
}
}
func BenchmarkRefererParser(b *testing.B) {
refererParser := newRefererParser()
u1 := getURL("https://www.google.com")
u2 := getURL("https://www.google.com")
for n := 0; n < b.N; n++ {
refererParser.parse(u1, u2)
}
}