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
Łukasz Nowak
caddy
Commits
2d5320c4
Commit
2d5320c4
authored
Jul 18, 2015
by
Maxime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test for the browse directive
Created sample files for the test
parent
2fa6e278
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
0 deletions
+91
-0
middleware/browse/browse_test.go
middleware/browse/browse_test.go
+61
-0
middleware/browse/header.html
middleware/browse/header.html
+1
-0
middleware/browse/photos.tpl
middleware/browse/photos.tpl
+13
-0
middleware/browse/photos/test.html
middleware/browse/photos/test.html
+8
-0
middleware/browse/photos/test2.html
middleware/browse/photos/test2.html
+8
-0
No files found.
middleware/browse/browse_test.go
View file @
2d5320c4
package
browse
import
(
"net/http"
"net/http/httptest"
"sort"
"testing"
"text/template"
"time"
"github.com/mholt/caddy/middleware"
)
// "sort" package has "IsSorted" function, but no "IsReversed";
...
...
@@ -94,3 +99,59 @@ func TestSort(t *testing.T) {
t
.
Errorf
(
"The listing isn't reversed by time: %v"
,
listing
.
Items
)
}
}
func
TestBrowseTemplate
(
t
*
testing
.
T
)
{
tmpl
,
err
:=
template
.
ParseFiles
(
"photos.tpl"
)
if
err
!=
nil
{
t
.
Fatalf
(
"An error occured while parsing the template: %v"
,
err
)
}
b
:=
Browse
{
Next
:
middleware
.
HandlerFunc
(
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
(
int
,
error
)
{
t
.
Fatalf
(
"Next shouldn't be called"
)
return
0
,
nil
}),
Root
:
"."
,
Configs
:
[]
Config
{
Config
{
PathScope
:
"/photos"
,
Template
:
tmpl
,
},
},
}
req
,
err
:=
http
.
NewRequest
(
"GET"
,
"/photos/"
,
nil
)
if
err
!=
nil
{
t
.
Fatalf
(
"Test: Could not create HTTP request: %v"
,
err
)
}
rec
:=
httptest
.
NewRecorder
()
b
.
ServeHTTP
(
rec
,
req
)
if
rec
.
Code
!=
http
.
StatusOK
{
t
.
Fatalf
(
"Wrong status, expected %d, got %d"
,
http
.
StatusOK
,
rec
.
Code
)
}
respBody
:=
rec
.
Body
.
String
()
expectedBody
:=
`<!DOCTYPE html>
<html>
<head>
<title>Template</title>
</head>
<body>
<h1>Header</h1>
<h1>/photos/</h1>
<a href="test.html">test.html</a><br>
<a href="test2.html">test2.html</a><br>
</body>
</html>
`
if
respBody
!=
expectedBody
{
t
.
Fatalf
(
"Expected body: %v got: %v"
,
expectedBody
,
respBody
)
}
}
middleware/browse/header.html
0 → 100644
View file @
2d5320c4
<h1>
Header
</h1>
middleware/browse/photos.tpl
0 → 100644
View file @
2d5320c4
<!DOCTYPE html>
<html>
<head>
<title>
Template
</title>
</head>
<body>
{{.Include "header.html"}}
<h1>
{{.Path}}
</h1>
{
{
range
.
Items
}
}
<a
href=
"{{.URL}}"
>
{{.Name}}
</a><br>
{
{
end
}
}
</body>
</html>
middleware/browse/photos/test.html
0 → 100644
View file @
2d5320c4
<!DOCTYPE html>
<html>
<head>
<title>
Test
</title>
</head>
<body>
</body>
</html>
middleware/browse/photos/test2.html
0 → 100644
View file @
2d5320c4
<!DOCTYPE html>
<html>
<head>
<title>
Test 2
</title>
</head>
<body>
</body>
</html>
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