This repository has been archived by the owner on Oct 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
url_test.go
58 lines (49 loc) · 1.54 KB
/
url_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
package rewrite
import (
"testing"
)
func TestUrlRewriter(t *testing.T) {
cases := stringTestCases([]stringTestCase{
{"", ""},
{"http://youtube.com", "http://youtube.com"},
{"https://a.com", "http://b.tv"},
{"http://a.com/", "http://b.tv/"},
{"/relative/url", "http://b.tv/relative/url"},
{"http://a.com/path?query=a", "http://b.tv/path?query=a"},
})
rw := NewUrlRewriter("http://a.com", "http://b.tv")
testRewriteCases(t, rw, cases)
}
func TestSchemeChangeUrlRewriter(t *testing.T) {
cases := stringTestCases([]stringTestCase{
{"", ""},
{"http://youtube.com", "http://youtube.com"},
{"http://a.com", "https://b.tv"},
{"/relative/url", "https://b.tv/relative/url"},
{"https://a.com/path?query=a", "https://b.tv/path?query=a"},
})
rw := NewUrlRewriter("http://a.com", "https://b.tv")
testRewriteCases(t, rw, cases)
}
func TestRelativeUrlRewriter(t *testing.T) {
cases := stringTestCases([]stringTestCase{
{"", ""},
{"http://youtube.com", "http://youtube.com"},
{"http://a.com", "."},
{"/relative/url", "./relative/url"},
{"https://a.com/path?query=a", "./path?query=a"},
})
rw := NewRelativeUrlRewriter("http://a.com")
testRewriteCases(t, rw, cases)
}
func TestHostRelativeUrlRewriter(t *testing.T) {
cases := stringTestCases([]stringTestCase{
{"", ""},
{"http://youtube.com", "../youtube.com"},
{"http://a.com", "../a.com"},
{"/relative/url", "../a.com/relative/url"},
{"https://a.com/path?query=a", "../a.com/path?query=a"},
})
rw := NewHostRelativeUrlRewriter("http://a.com")
testRewriteCases(t, rw, cases)
}