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
0d5a8a73
Commit
0d5a8a73
authored
May 09, 2015
by
Peter Hellberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
headers: Test for Headers and headersParse funcs
parent
df6efe5d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
config/setup/headers_test.go
config/setup/headers_test.go
+85
-0
No files found.
config/setup/headers_test.go
0 → 100644
View file @
0d5a8a73
package
setup
import
(
"fmt"
"testing"
"github.com/mholt/caddy/middleware/headers"
)
func
TestHeaders
(
t
*
testing
.
T
)
{
c
:=
newTestController
(
`header / Foo Bar`
)
mid
,
err
:=
Headers
(
c
)
if
err
!=
nil
{
t
.
Errorf
(
"Expected no errors, but got: %v"
,
err
)
}
if
mid
==
nil
{
t
.
Fatal
(
"Expected middleware, was nil instead"
)
}
handler
:=
mid
(
emptyNext
)
myHandler
,
ok
:=
handler
.
(
headers
.
Headers
)
if
!
ok
{
t
.
Fatalf
(
"Expected handler to be type BasicAuth, got: %#v"
,
handler
)
}
if
!
sameNext
(
myHandler
.
Next
,
emptyNext
)
{
t
.
Error
(
"'Next' field of handler was not set properly"
)
}
}
func
TestHeadersParse
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
input
string
shouldErr
bool
expected
[]
headers
.
Rule
}{
{
`header /foo Foo "Bar Baz"`
,
false
,
[]
headers
.
Rule
{
{
Path
:
"/foo"
,
Headers
:
[]
headers
.
Header
{
{
"Foo"
,
"Bar Baz"
},
}},
}},
{
`header /bar { Foo "Bar Baz" Baz Qux }`
,
false
,
[]
headers
.
Rule
{
{
Path
:
"/bar"
,
Headers
:
[]
headers
.
Header
{
{
"Foo"
,
"Bar Baz"
},
{
"Baz"
,
"Qux"
},
}},
}},
}
for
i
,
test
:=
range
tests
{
c
:=
newTestController
(
test
.
input
)
actual
,
err
:=
headersParse
(
c
)
if
err
==
nil
&&
test
.
shouldErr
{
t
.
Errorf
(
"Test %d didn't error, but it should have"
,
i
)
}
else
if
err
!=
nil
&&
!
test
.
shouldErr
{
t
.
Errorf
(
"Test %d errored, but it shouldn't have; got '%v'"
,
i
,
err
)
}
if
len
(
actual
)
!=
len
(
test
.
expected
)
{
t
.
Fatalf
(
"Test %d expected %d rules, but got %d"
,
i
,
len
(
test
.
expected
),
len
(
actual
))
}
for
j
,
expectedRule
:=
range
test
.
expected
{
actualRule
:=
actual
[
j
]
if
actualRule
.
Path
!=
expectedRule
.
Path
{
t
.
Errorf
(
"Test %d, rule %d: Expected path %s, but got %s"
,
i
,
j
,
expectedRule
.
Path
,
actualRule
.
Path
)
}
expectedHeaders
:=
fmt
.
Sprintf
(
"%v"
,
expectedRule
.
Headers
)
actualHeaders
:=
fmt
.
Sprintf
(
"%v"
,
actualRule
.
Headers
)
if
actualHeaders
!=
expectedHeaders
{
t
.
Errorf
(
"Test %d, rule %d: Expected headers %s, but got %s"
,
i
,
j
,
expectedHeaders
,
actualHeaders
)
}
}
}
}
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