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
Łukasz Nowak
caddy
Commits
63356774
Commit
63356774
authored
Jan 08, 2017
by
Tw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
proxy: refactor TestUpstreamHeadersUpdate and TestDownstreamHeadersUpdate
Signed-off-by:
Tw
<
tw19881113@gmail.com
>
parent
c3523305
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
80 deletions
+24
-80
caddyhttp/proxy/proxy_test.go
caddyhttp/proxy/proxy_test.go
+24
-80
No files found.
caddyhttp/proxy/proxy_test.go
View file @
63356774
...
...
@@ -532,43 +532,18 @@ func TestUpstreamHeadersUpdate(t *testing.T) {
replacer
:=
httpserver
.
NewReplacer
(
r
,
nil
,
""
)
headerKey
:=
"Merge-Me"
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"
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
=
"Add-Empty"
if
_
,
ok
:=
actualHeaders
[
headerKey
];
ok
{
t
.
Errorf
(
"Request sent to upstream backend should not contain empty %v header"
,
headerKey
)
}
headerKey
=
"Remove-Me"
if
_
,
ok
:=
actualHeaders
[
headerKey
];
ok
{
t
.
Errorf
(
"Request sent to upstream backend should not contain %v header"
,
headerKey
)
}
headerKey
=
"Replace-Me"
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
)
}
headerKey
=
"Clear-Me"
if
_
,
ok
:=
actualHeaders
[
headerKey
];
ok
{
t
.
Errorf
(
"Request sent to upstream backend should not contain empty %v header"
,
headerKey
)
for
headerKey
,
expect
:=
range
map
[
string
][]
string
{
"Merge-Me"
:
{
"Initial"
,
"Merge-Value"
},
"Add-Me"
:
{
"Add-Value"
},
"Add-Empty"
:
nil
,
"Remove-Me"
:
nil
,
"Replace-Me"
:
{
replacer
.
Replace
(
"{hostname}"
)},
"Clear-Me"
:
nil
,
}
{
if
got
:=
actualHeaders
[
headerKey
];
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Upstream request does not contain expected %v header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
}
}
if
actualHost
!=
expectHost
{
...
...
@@ -617,49 +592,18 @@ func TestDownstreamHeadersUpdate(t *testing.T) {
replacer
:=
httpserver
.
NewReplacer
(
r
,
nil
,
""
)
actualHeaders
:=
w
.
Header
()
headerKey
:=
"Merge-Me"
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"
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"
if
_
,
ok
:=
actualHeaders
[
headerKey
];
ok
{
t
.
Errorf
(
"Downstream response should not contain %v header received from upstream"
,
headerKey
)
}
headerKey
=
"Replace-Me"
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
)
}
headerKey
=
"Content-Type"
got
=
actualHeaders
[
headerKey
]
expect
=
[]
string
{
"text/css"
}
if
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Downstream response does not contain expected %s header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
}
headerKey
=
"Overwrite-Me"
got
=
actualHeaders
[
headerKey
]
expect
=
[]
string
{
"Overwrite-Value"
}
if
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Downstream response does not contain expected %s header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
for
headerKey
,
expect
:=
range
map
[
string
][]
string
{
"Merge-Me"
:
{
"Initial"
,
"Merge-Value"
},
"Add-Me"
:
{
"Add-Value"
},
"Remove-Me"
:
nil
,
"Replace-Me"
:
{
replacer
.
Replace
(
"{hostname}"
)},
"Content-Type"
:
{
"text/css"
},
"Overwrite-Me"
:
{
"Overwrite-Value"
},
}
{
if
got
:=
actualHeaders
[
headerKey
];
!
reflect
.
DeepEqual
(
got
,
expect
)
{
t
.
Errorf
(
"Downstream response does not contain expected %s header: expect %v, but got %v"
,
headerKey
,
expect
,
got
)
}
}
}
...
...
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