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
9995466a
Commit
9995466a
authored
Jun 27, 2015
by
Karthic Rao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial Test case for config/setup/templates.go
parent
f424f450
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
5 deletions
+48
-5
config/setup/templates.go
config/setup/templates.go
+5
-5
config/setup/templates_test.go
config/setup/templates_test.go
+43
-0
No files found.
config/setup/templates.go
View file @
9995466a
...
...
@@ -39,11 +39,11 @@ func templatesParse(c *Controller) ([]templates.Rule, error) {
// Any remaining arguments are extensions
rule
.
Extensions
=
c
.
RemainingArgs
()
if
len
(
rule
.
Extensions
)
==
0
{
rule
.
Extensions
=
default
Extensions
rule
.
Extensions
=
DefaultTemplate
Extensions
}
}
else
{
rule
.
Path
=
default
Path
rule
.
Extensions
=
default
Extensions
rule
.
Path
=
DefaultTemplate
Path
rule
.
Extensions
=
DefaultTemplate
Extensions
}
for
_
,
ext
:=
range
rule
.
Extensions
{
...
...
@@ -56,6 +56,6 @@ func templatesParse(c *Controller) ([]templates.Rule, error) {
return
rules
,
nil
}
const
default
Path
=
"/"
const
DefaultTemplate
Path
=
"/"
var
default
Extensions
=
[]
string
{
".html"
,
".htm"
,
".tmpl"
,
".tpl"
,
".txt"
}
var
DefaultTemplate
Extensions
=
[]
string
{
".html"
,
".htm"
,
".tmpl"
,
".tpl"
,
".txt"
}
config/setup/templates_test.go
0 → 100644
View file @
9995466a
package
setup
import
(
"fmt"
"github.com/mholt/caddy/middleware/templates"
"testing"
)
func
TestTemplates
(
t
*
testing
.
T
)
{
c
:=
NewTestController
(
`templates`
)
mid
,
err
:=
Templates
(
c
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected no errors, got: %v"
,
err
)
}
if
mid
==
nil
{
t
.
Fatal
(
"Expected middleware, was nil instead"
)
}
handler
:=
mid
(
EmptyNext
)
myHandler
,
ok
:=
handler
.
(
templates
.
Templates
)
if
!
ok
{
t
.
Fatalf
(
"Expected handler to be type Templates, got: %#v"
,
handler
)
}
if
myHandler
.
Rules
[
0
]
.
Path
!=
DefaultTemplatePath
{
t
.
Errorf
(
"Expected / as the default Path"
)
}
if
fmt
.
Sprint
(
myHandler
.
Rules
[
0
]
.
Extensions
)
!=
fmt
.
Sprint
(
DefaultTemplateExtensions
)
{
t
.
Errorf
(
"Expected %v to be the Default Extensions"
,
DefaultTemplateExtensions
)
}
var
indexFiles
[]
string
for
_
,
extension
:=
range
DefaultTemplateExtensions
{
indexFiles
=
append
(
indexFiles
,
"index"
+
extension
)
}
if
fmt
.
Sprint
(
myHandler
.
Rules
[
0
]
.
IndexFiles
)
!=
fmt
.
Sprint
(
indexFiles
)
{
t
.
Errorf
(
"Expected %v to be the Default Index files"
,
indexFiles
)
}
}
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