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
1017142d
Commit
1017142d
authored
Nov 07, 2015
by
Dipen Patel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made style adjustments to browse and redir tests
parent
2b1cc77f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
38 deletions
+24
-38
caddy/setup/browse_test.go
caddy/setup/browse_test.go
+12
-23
caddy/setup/redir_test.go
caddy/setup/redir_test.go
+12
-15
No files found.
caddy/setup/browse_test.go
View file @
1017142d
...
@@ -5,13 +5,10 @@ import (
...
@@ -5,13 +5,10 @@ import (
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strconv"
"strings"
"testing"
"testing"
"time"
"time"
"github.com/mholt/caddy/caddy/parse"
"github.com/mholt/caddy/middleware/browse"
"github.com/mholt/caddy/middleware/browse"
"github.com/mholt/caddy/server"
)
)
func
TestBrowse
(
t
*
testing
.
T
)
{
func
TestBrowse
(
t
*
testing
.
T
)
{
...
@@ -30,45 +27,37 @@ func TestBrowse(t *testing.T) {
...
@@ -30,45 +27,37 @@ func TestBrowse(t *testing.T) {
tempTemplatePath
:=
filepath
.
Join
(
"."
,
tempTemplate
.
Name
())
tempTemplatePath
:=
filepath
.
Join
(
"."
,
tempTemplate
.
Name
())
testTokens
:=
[]
string
{
for
i
,
test
:=
range
[]
struct
{
"browse "
+
tempDirPath
+
"
\n
browse ."
,
input
string
"browse /"
,
"browse . "
+
tempTemplatePath
,
"browse . "
+
nonExistantDirPath
,
"browse "
+
tempDirPath
+
"
\n
browse "
+
tempDirPath
,
}
tests
:=
[]
struct
{
expectedPathScope
[]
string
expectedPathScope
[]
string
shouldErr
bool
shouldErr
bool
}{
}{
// test case #0 tests handling of multiple pathscopes
// test case #0 tests handling of multiple pathscopes
{[]
string
{
tempDirPath
,
"."
},
false
},
{
"browse "
+
tempDirPath
+
"
\n
browse ."
,
[]
string
{
tempDirPath
,
"."
},
false
},
// test case #1 tests instantiation of browse.Config with default values
// test case #1 tests instantiation of browse.Config with default values
{[]
string
{
"/"
},
false
},
{
"browse /"
,
[]
string
{
"/"
},
false
},
// test case #2 tests detectaction of custom template
// test case #2 tests detectaction of custom template
{[]
string
{
"."
},
false
},
{
"browse . "
+
tempTemplatePath
,
[]
string
{
"."
},
false
},
// test case #3 tests detection of non-existant template
// test case #3 tests detection of non-existant template
{
nil
,
true
},
{
"browse . "
+
nonExistantDirPath
,
nil
,
true
},
// test case #4 tests detection of duplicate pathscopes
// test case #4 tests detection of duplicate pathscopes
{
nil
,
true
},
{
"browse "
+
tempDirPath
+
"
\n
browse "
+
tempDirPath
,
nil
,
true
},
}
}
{
for
i
,
test
:=
range
tests
{
// c := &Controller{Config: &server.Config{Root: "."}, Dispenser: parse.NewDispenser("", strings.NewReader(testTokens[i]))}
c
:=
&
Controller
{
Config
:
&
server
.
Config
{
Root
:
"."
},
Dispenser
:
parse
.
NewDispenser
(
""
,
strings
.
NewReader
(
testTokens
[
i
]))}
recievedFunc
,
err
:=
Browse
(
NewTestController
(
test
.
input
))
retrievedFunc
,
err
:=
Browse
(
c
)
if
err
!=
nil
&&
!
test
.
shouldErr
{
if
err
!=
nil
&&
!
test
.
shouldErr
{
t
.
Errorf
(
"Test case #%d recieved an error of %v"
,
i
,
err
)
t
.
Errorf
(
"Test case #%d recieved an error of %v"
,
i
,
err
)
}
}
if
test
.
expectedPathScope
==
nil
{
if
test
.
expectedPathScope
==
nil
{
continue
continue
}
}
re
trievedConfigs
:=
retr
ievedFunc
(
nil
)
.
(
browse
.
Browse
)
.
Configs
re
cievedConfigs
:=
rec
ievedFunc
(
nil
)
.
(
browse
.
Browse
)
.
Configs
for
j
,
config
:=
range
re
tr
ievedConfigs
{
for
j
,
config
:=
range
re
c
ievedConfigs
{
if
config
.
PathScope
!=
test
.
expectedPathScope
[
j
]
{
if
config
.
PathScope
!=
test
.
expectedPathScope
[
j
]
{
t
.
Errorf
(
"Test case #%d expected a pathscope of %v, but got %v"
,
i
,
test
.
expectedPathScope
,
config
.
PathScope
)
t
.
Errorf
(
"Test case #%d expected a pathscope of %v, but got %v"
,
i
,
test
.
expectedPathScope
,
config
.
PathScope
)
}
}
...
...
caddy/setup/redir_test.go
View file @
1017142d
...
@@ -8,8 +8,8 @@ import (
...
@@ -8,8 +8,8 @@ import (
func
TestRedir
(
t
*
testing
.
T
)
{
func
TestRedir
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
for
j
,
test
:=
range
[]
struct
{
testToken
string
input
string
shouldErr
bool
shouldErr
bool
expectedRules
[]
redirect
.
Rule
expectedRules
[]
redirect
.
Rule
}{
}{
...
@@ -42,27 +42,24 @@ func TestRedir(t *testing.T) {
...
@@ -42,27 +42,24 @@ func TestRedir(t *testing.T) {
// test case #9 tests the detection of duplicate redirections
// test case #9 tests the detection of duplicate redirections
{
"redir {
\n
/bar /foo 304
\n
} redir {
\n
/bar /foo 304
\n
}"
,
true
,
[]
redirect
.
Rule
{
redirect
.
Rule
{}}},
{
"redir {
\n
/bar /foo 304
\n
} redir {
\n
/bar /foo 304
\n
}"
,
true
,
[]
redirect
.
Rule
{
redirect
.
Rule
{}}},
}
}
{
recievedFunc
,
err
:=
Redir
(
NewTestController
(
test
.
input
))
for
j
,
test
:=
range
tests
{
c
:=
NewTestController
(
test
.
testToken
)
retrievedFunc
,
err
:=
Redir
(
c
)
if
err
!=
nil
&&
!
test
.
shouldErr
{
if
err
!=
nil
&&
!
test
.
shouldErr
{
t
.
Errorf
(
"Test case #%d recieved an error of %v"
,
j
,
err
)
t
.
Errorf
(
"Test case #%d recieved an error of %v"
,
j
,
err
)
}
else
if
test
.
shouldErr
{
}
else
if
test
.
shouldErr
{
continue
continue
}
}
re
trievedRules
:=
retr
ievedFunc
(
nil
)
.
(
redirect
.
Redirect
)
.
Rules
re
cievedRules
:=
rec
ievedFunc
(
nil
)
.
(
redirect
.
Redirect
)
.
Rules
for
i
,
re
trievedRule
:=
range
retr
ievedRules
{
for
i
,
re
cievedRule
:=
range
rec
ievedRules
{
if
re
tr
ievedRule
.
FromPath
!=
test
.
expectedRules
[
i
]
.
FromPath
{
if
re
c
ievedRule
.
FromPath
!=
test
.
expectedRules
[
i
]
.
FromPath
{
t
.
Errorf
(
"Test case #%d.%d expected a from path of %s, but recieved a from path of %s"
,
j
,
i
,
test
.
expectedRules
[
i
]
.
FromPath
,
re
tr
ievedRule
.
FromPath
)
t
.
Errorf
(
"Test case #%d.%d expected a from path of %s, but recieved a from path of %s"
,
j
,
i
,
test
.
expectedRules
[
i
]
.
FromPath
,
re
c
ievedRule
.
FromPath
)
}
}
if
re
tr
ievedRule
.
To
!=
test
.
expectedRules
[
i
]
.
To
{
if
re
c
ievedRule
.
To
!=
test
.
expectedRules
[
i
]
.
To
{
t
.
Errorf
(
"Test case #%d.%d expected a TO path of %s, but recieved a TO path of %s"
,
j
,
i
,
test
.
expectedRules
[
i
]
.
To
,
re
tr
ievedRule
.
To
)
t
.
Errorf
(
"Test case #%d.%d expected a TO path of %s, but recieved a TO path of %s"
,
j
,
i
,
test
.
expectedRules
[
i
]
.
To
,
re
c
ievedRule
.
To
)
}
}
if
re
tr
ievedRule
.
Code
!=
test
.
expectedRules
[
i
]
.
Code
{
if
re
c
ievedRule
.
Code
!=
test
.
expectedRules
[
i
]
.
Code
{
t
.
Errorf
(
"Test case #%d.%d expected a HTTP status code of %d, but recieved a code of %d"
,
j
,
i
,
test
.
expectedRules
[
i
]
.
Code
,
re
tr
ievedRule
.
Code
)
t
.
Errorf
(
"Test case #%d.%d expected a HTTP status code of %d, but recieved a code of %d"
,
j
,
i
,
test
.
expectedRules
[
i
]
.
Code
,
re
c
ievedRule
.
Code
)
}
}
}
}
}
}
...
...
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