-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect_test.go
101 lines (91 loc) · 1.9 KB
/
redirect_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
package pgs
import (
"testing"
"github.com/google/go-cmp/cmp"
)
type RedirectFixture struct {
name string
input string
expect []*RedirectRule
shouldError bool
}
func TestParseRedirectText(t *testing.T) {
empty := map[string]string{}
spa := RedirectFixture{
name: "spa",
input: "/* /index.html 200",
expect: []*RedirectRule{
{
From: "/*",
To: "/index.html",
Status: 200,
Query: empty,
Conditions: empty,
},
},
}
withStatus := RedirectFixture{
name: "with-status",
input: "/wow /index.html 301",
expect: []*RedirectRule{
{
From: "/wow",
To: "/index.html",
Status: 301,
Query: empty,
Conditions: empty,
},
},
}
noStatus := RedirectFixture{
name: "no-status",
input: "/wow /index.html",
expect: []*RedirectRule{
{
From: "/wow",
To: "/index.html",
Status: 301,
Query: empty,
Conditions: empty,
},
},
}
absoluteUriNoProto := RedirectFixture{
name: "absolute-uri-no-proto",
input: "/* www.example.com 301",
expect: []*RedirectRule{},
shouldError: true,
}
absoluteUriWithProto := RedirectFixture{
name: "absolute-uri-no-proto",
input: "/* https://www.example.com 301",
expect: []*RedirectRule{
{
From: "/*",
To: "https://www.example.com",
Status: 301,
Query: empty,
Conditions: empty,
},
},
}
fixtures := []RedirectFixture{
spa,
withStatus,
noStatus,
absoluteUriNoProto,
absoluteUriWithProto,
}
for _, fixture := range fixtures {
t.Run(fixture.name, func(t *testing.T) {
results, err := parseRedirectText(fixture.input)
if err != nil && !fixture.shouldError {
t.Error(err)
}
if cmp.Equal(results, fixture.expect) == false {
//nolint
t.Fatalf(cmp.Diff(fixture.expect, results))
}
})
}
}