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
c12257a1
Commit
c12257a1
authored
Jun 26, 2015
by
Matt Holt
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #168 from Karthic-Hackintosh/master
Initial Test case for config/setup/templates.go
parents
f424f450
e039577d
Changes
2
Show 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 @
c12257a1
...
...
@@ -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
=
defaultExtensions
rule
.
Extensions
=
default
Template
Extensions
}
}
else
{
rule
.
Path
=
defaultPath
rule
.
Extensions
=
defaultExtensions
rule
.
Path
=
default
Template
Path
rule
.
Extensions
=
default
Template
Extensions
}
for
_
,
ext
:=
range
rule
.
Extensions
{
...
...
@@ -56,6 +56,6 @@ func templatesParse(c *Controller) ([]templates.Rule, error) {
return
rules
,
nil
}
const
defaultPath
=
"/"
const
default
Template
Path
=
"/"
var
defaultExtensions
=
[]
string
{
".html"
,
".htm"
,
".tmpl"
,
".tpl"
,
".txt"
}
var
default
Template
Extensions
=
[]
string
{
".html"
,
".htm"
,
".tmpl"
,
".tpl"
,
".txt"
}
config/setup/templates_test.go
0 → 100644
View file @
c12257a1
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