Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
caddy
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
caddy
Commits
33fa29fd
Commit
33fa29fd
authored
Jul 10, 2015
by
Peter Hellberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
extensions: Initial tests
parent
d3c22937
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
0 deletions
+55
-0
middleware/extensions/ext_test.go
middleware/extensions/ext_test.go
+55
-0
No files found.
middleware/extensions/ext_test.go
0 → 100644
View file @
33fa29fd
package
extensions
import
(
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"
"github.com/mholt/caddy/middleware"
)
func
TestExtensions
(
t
*
testing
.
T
)
{
rootDir
:=
os
.
TempDir
()
// create a temporary page
path
:=
filepath
.
Join
(
rootDir
,
"extensions_test.html"
)
_
,
err
:=
os
.
Create
(
path
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
defer
os
.
Remove
(
path
)
for
i
,
test
:=
range
[]
struct
{
path
string
extensions
[]
string
expectedURL
string
}{
{
"/extensions_test"
,
[]
string
{
".html"
},
"/extensions_test.html"
},
{
"/extensions_test/"
,
[]
string
{
".html"
},
"/extensions_test/"
},
{
"/extensions_test"
,
[]
string
{
".json"
},
"/extensions_test"
},
{
"/another_test"
,
[]
string
{
".html"
},
"/another_test"
},
}
{
ex
:=
Ext
{
Next
:
middleware
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
return
0
,
nil
}),
Root
:
rootDir
,
Extensions
:
test
.
extensions
,
}
req
,
err
:=
http
.
NewRequest
(
"GET"
,
test
.
path
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"Test %d: Could not create HTTP request: %v"
,
i
,
err
)
}
rec
:=
httptest
.
NewRecorder
()
ex
.
ServeHTTP
(
rec
,
req
)
if
got
:=
req
.
URL
.
String
();
got
!=
test
.
expectedURL
{
t
.
Fatalf
(
"Test %d: Got unexpected request URL: %q, wanted %q"
,
i
,
got
,
test
.
expectedURL
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment