-
Notifications
You must be signed in to change notification settings - Fork 35
/
pathinfo_test.go
139 lines (124 loc) · 4.89 KB
/
pathinfo_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
package gold
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestPathInfoWithoutTrailingSlash(t *testing.T) {
sroot := serverDefaultRoot()
req := &httpRequest{nil, handler, "", "", "", false}
p, err := req.pathInfo(testServer.URL)
assert.Nil(t, err)
assert.Equal(t, testServer.URL+"/", p.URI)
assert.Equal(t, testServer.URL, p.Base)
assert.Equal(t, "", p.Path)
assert.Equal(t, sroot, p.File)
assert.Equal(t, testServer.URL+"/"+config.ACLSuffix, p.AclURI)
assert.Equal(t, sroot+config.ACLSuffix, p.AclFile)
assert.Equal(t, testServer.URL+"/"+config.MetaSuffix, p.MetaURI)
assert.Equal(t, sroot+config.MetaSuffix, p.MetaFile)
assert.Empty(t, p.Extension)
assert.True(t, p.Exists)
}
func TestPathInfoWithTrailingSlash(t *testing.T) {
sroot := serverDefaultRoot()
req := &httpRequest{nil, handler, "", "", "", false}
p, err := req.pathInfo(testServer.URL + "/")
assert.Nil(t, err)
assert.Equal(t, testServer.URL, p.Base)
assert.Equal(t, testServer.URL+"/", p.URI)
assert.Equal(t, "", p.Path)
assert.Equal(t, sroot, p.File)
assert.Equal(t, testServer.URL+"/"+config.ACLSuffix, p.AclURI)
assert.Equal(t, sroot+config.ACLSuffix, p.AclFile)
assert.Equal(t, testServer.URL+"/"+config.MetaSuffix, p.MetaURI)
assert.Equal(t, sroot+config.MetaSuffix, p.MetaFile)
assert.Empty(t, p.Extension)
assert.True(t, p.Exists)
}
func TestPathInfoWithPath(t *testing.T) {
path := testServer.URL + "/_test/"
sroot := serverDefaultRoot()
req := &httpRequest{nil, handler, "", "", "", false}
p, err := req.pathInfo(path)
assert.Nil(t, err)
assert.Equal(t, path, p.URI)
assert.Equal(t, testServer.URL, p.Base)
assert.Equal(t, "_test/", p.Path)
assert.Equal(t, sroot+"_test/", p.File)
assert.Equal(t, path+config.ACLSuffix, p.AclURI)
assert.Equal(t, sroot+"_test/"+config.ACLSuffix, p.AclFile)
assert.Equal(t, path+config.MetaSuffix, p.MetaURI)
assert.Equal(t, sroot+"_test/"+config.MetaSuffix, p.MetaFile)
assert.Empty(t, p.Extension)
assert.True(t, p.Exists)
}
func TestPathInfoWithPathAndChildDir(t *testing.T) {
path := testServer.URL + "/_test/"
sroot := serverDefaultRoot()
req := &httpRequest{nil, handler, "", "", "", false}
p, err := req.pathInfo(path + "dir/")
assert.Nil(t, err)
assert.Equal(t, path+"dir/", p.URI)
assert.Equal(t, testServer.URL, p.Base)
assert.Equal(t, "_test/dir/", p.Path)
assert.Equal(t, path, p.ParentURI)
assert.Equal(t, sroot+"_test/dir/", p.File)
assert.Equal(t, path+"dir/"+config.ACLSuffix, p.AclURI)
assert.Equal(t, sroot+"_test/dir/"+config.ACLSuffix, p.AclFile)
assert.Equal(t, path+"dir/"+config.MetaSuffix, p.MetaURI)
assert.Equal(t, sroot+"_test/dir/"+config.MetaSuffix, p.MetaFile)
assert.Empty(t, p.Extension)
assert.False(t, p.Exists)
}
func TestPathInfoWithPathAndChildFile(t *testing.T) {
path := testServer.URL + "/_test/"
sroot := serverDefaultRoot()
req := &httpRequest{nil, handler, "", "", "", false}
p, err := req.pathInfo(path + "abc")
assert.Nil(t, err)
assert.Equal(t, path+"abc", p.URI)
assert.Equal(t, testServer.URL, p.Base)
assert.Equal(t, "_test/abc", p.Path)
assert.Equal(t, path, p.ParentURI)
assert.Equal(t, sroot+"_test/abc", p.File)
assert.Equal(t, path+"abc"+config.ACLSuffix, p.AclURI)
assert.Equal(t, sroot+"_test/abc"+config.ACLSuffix, p.AclFile)
assert.Equal(t, path+"abc"+config.MetaSuffix, p.MetaURI)
assert.Equal(t, sroot+"_test/abc"+config.MetaSuffix, p.MetaFile)
assert.Empty(t, p.Extension)
assert.False(t, p.Exists)
}
func TestPathInfoWithPathAndACLSuffix(t *testing.T) {
path := testServer.URL + "/_test/"
sroot := serverDefaultRoot()
req := &httpRequest{nil, handler, "", "", "", false}
p, err := req.pathInfo(path + config.ACLSuffix)
assert.Nil(t, err)
assert.Equal(t, path+config.ACLSuffix, p.URI)
assert.Equal(t, testServer.URL, p.Base)
assert.Equal(t, "_test/"+config.ACLSuffix, p.Path)
assert.Equal(t, sroot+"_test/"+config.ACLSuffix, p.File)
assert.Equal(t, path+config.ACLSuffix, p.AclURI)
assert.Equal(t, sroot+"_test/"+config.ACLSuffix, p.AclFile)
assert.Equal(t, path+config.ACLSuffix, p.MetaURI)
assert.Equal(t, sroot+"_test/"+config.ACLSuffix, p.MetaFile)
assert.Equal(t, config.ACLSuffix, p.Extension)
assert.False(t, p.Exists)
}
func TestPathInfoWithPathAndMetaSuffix(t *testing.T) {
path := testServer.URL + "/_test/"
sroot := serverDefaultRoot()
req := &httpRequest{nil, handler, "", "", "", false}
p, err := req.pathInfo(path + config.MetaSuffix)
assert.Nil(t, err)
assert.Equal(t, path+config.MetaSuffix, p.URI)
assert.Equal(t, testServer.URL, p.Base)
assert.Equal(t, "_test/"+config.MetaSuffix, p.Path)
assert.Equal(t, sroot+"_test/"+config.MetaSuffix, p.File)
assert.Equal(t, path+config.MetaSuffix+config.ACLSuffix, p.AclURI)
assert.Equal(t, sroot+"_test/"+config.MetaSuffix+config.ACLSuffix, p.AclFile)
assert.Equal(t, path+config.MetaSuffix, p.MetaURI)
assert.Equal(t, sroot+"_test/"+config.MetaSuffix, p.MetaFile)
assert.Equal(t, config.MetaSuffix, p.Extension)
assert.False(t, p.Exists)
}