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
4670d13c
Commit
4670d13c
authored
Sep 16, 2016
by
Tw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy: fix checking error in TestDownstreamHeadersUpdate and TestUpstreamHeadersUpdate
Signed-off-by:
Tw
<
tw19881113@gmail.com
>
parent
bac54de9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
27 deletions
+31
-27
caddyhttp/proxy/proxy_test.go
caddyhttp/proxy/proxy_test.go
+31
-27
No files found.
caddyhttp/proxy/proxy_test.go
View file @
4670d13c
...
...
@@ -13,6 +13,7 @@ import (
"net/url"
"os"
"path/filepath"
"reflect"
"runtime"
"strings"
"sync/atomic"
...
...
@@ -407,16 +408,19 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
replacer
:=
httpserver
.
NewReplacer
(
r
,
nil
,
""
)
headerKey
:=
"Merge-Me"
values
,
ok
:=
actualHeaders
[
headerKey
]
if
!
ok
{
t
.
Errorf
(
"Request sent to upstream backend does not contain expected %v header. Expected header to be added"
,
headerKey
)
}
else
if
len
(
values
)
<
2
&&
(
values
[
0
]
!=
"Initial"
||
values
[
1
]
!=
replacer
.
Replace
(
"{hostname}"
))
{
t
.
Errorf
(
"Values for proxy header `+Merge-Me` should be merged. Got %v"
,
values
)
got
:=
actualHeaders
[
headerKey
]
expect
:=
[]
string
{
"Initial"
,
"Merge-Value"
}
if
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Request sent to upstream backend does not contain expected %v header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
}
headerKey
=
"Add-Me"
if
_
,
ok
:=
actualHeaders
[
headerKey
];
!
ok
{
t
.
Errorf
(
"Request sent to upstream backend does not contain expected %v header"
,
headerKey
)
got
=
actualHeaders
[
headerKey
]
expect
=
[]
string
{
"Add-Value"
}
if
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Request sent to upstream backend does not contain expected %v header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
}
headerKey
=
"Remove-Me"
...
...
@@ -425,12 +429,11 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
}
headerKey
=
"Replace-Me"
headerValue
:=
replacer
.
Replace
(
"{hostname}"
)
value
,
ok
:=
actualHeaders
[
headerKey
]
if
!
ok
{
t
.
Errorf
(
"Request sent to upstream backend should not remove %v header"
,
headerKey
)
}
else
if
len
(
value
)
>
0
&&
headerValue
!=
value
[
0
]
{
t
.
Errorf
(
"Request sent to upstream backend should replace value of %v header with %v. Instead value was %v"
,
headerKey
,
headerValue
,
value
)
got
=
actualHeaders
[
headerKey
]
expect
=
[]
string
{
replacer
.
Replace
(
"{hostname}"
)}
if
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Request sent to upstream backend does not contain expected %v header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
}
if
actualHost
!=
expectHost
{
...
...
@@ -477,16 +480,19 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
actualHeaders
:=
w
.
Header
()
headerKey
:=
"Merge-Me"
values
,
ok
:=
actualHeaders
[
headerKey
]
if
!
ok
{
t
.
Errorf
(
"Downstream response does not contain expected %v header. Expected header should be added"
,
headerKey
)
}
else
if
len
(
values
)
<
2
&&
(
values
[
0
]
!=
"Initial"
||
values
[
1
]
!=
replacer
.
Replace
(
"{hostname}"
))
{
t
.
Errorf
(
"Values for header `+Merge-Me` should be merged. Got %v"
,
values
)
got
:=
actualHeaders
[
headerKey
]
expect
:=
[]
string
{
"Initial"
,
"Merge-Value"
}
if
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Downstream response does not contain expected %s header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
}
headerKey
=
"Add-Me"
if
_
,
ok
:=
actualHeaders
[
headerKey
];
!
ok
{
t
.
Errorf
(
"Downstream response does not contain expected %v header"
,
headerKey
)
got
=
actualHeaders
[
headerKey
]
expect
=
[]
string
{
"Add-Value"
}
if
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Downstream response does not contain expected %s header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
}
headerKey
=
"Remove-Me"
...
...
@@ -495,14 +501,12 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
}
headerKey
=
"Replace-Me"
headerValue
:=
replacer
.
Replace
(
"{hostname}"
)
value
,
ok
:=
actualHeaders
[
headerKey
]
if
!
ok
{
t
.
Errorf
(
"Downstream response should contain %v header and not remove it"
,
headerKey
)
}
else
if
len
(
value
)
>
0
&&
headerValue
!=
value
[
0
]
{
t
.
Errorf
(
"Downstream response should have header %v with value %v. Instead value was %v"
,
headerKey
,
headerValue
,
value
)
got
=
actualHeaders
[
headerKey
]
expect
=
[]
string
{
replacer
.
Replace
(
"{hostname}"
)}
if
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Downstream response does not contain expected %s header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
}
}
var
(
...
...
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