Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
k8s-crt-dnldr
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
k8s
k8s-crt-dnldr
Commits
09965460
Commit
09965460
authored
Jul 28, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
REST API: fix and test HEAD /v1/pems
parent
54459835
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
7 deletions
+32
-7
allpems_handler_test.go
pkg/rest/allpems_handler_test.go
+23
-3
handlers.go
pkg/rest/handlers.go
+9
-4
No files found.
pkg/rest/allpems_handler_test.go
View file @
09965460
...
...
@@ -281,14 +281,34 @@ func TestAllPems(t *testing.T) {
if
!
barFound
{
t
.
Errorf
(
"GET /v1/pems did not return bar: %#v"
,
allInfo
)
}
if
rr
.
Header
()
.
Get
(
"Content-Length"
)
!=
strconv
.
Itoa
(
rr
.
Body
.
Len
())
{
t
.
Errorf
(
"GET /v1/pems Content-Length: got %s want %d"
,
rr
.
Header
()
.
Get
(
"Content-Length"
),
rr
.
Body
.
Len
())
bodyLen
:=
strconv
.
Itoa
(
rr
.
Body
.
Len
())
if
rr
.
Header
()
.
Get
(
"Content-Length"
)
!=
bodyLen
{
t
.
Errorf
(
"GET /v1/pems Content-Length: got %s want %s"
,
rr
.
Header
()
.
Get
(
"Content-Length"
),
bodyLen
)
}
if
rr
.
Header
()
.
Get
(
"Content-Type"
)
!=
jsonContentType
{
t
.
Errorf
(
"GET /v1/pems Content-Type: got %s want %s"
,
rr
.
Header
()
.
Get
(
"Content-Type"
),
jsonContentType
)
}
req
=
httptest
.
NewRequest
(
http
.
MethodHead
,
"/v1/pems"
,
nil
)
rr
=
httptest
.
NewRecorder
()
hndlr
.
ServeHTTP
(
rr
,
req
)
if
rr
.
Code
!=
http
.
StatusOK
{
t
.
Errorf
(
"HEAD /v1/pems status: got %d want %d"
,
rr
.
Code
,
http
.
StatusOK
)
}
if
rr
.
Body
.
Len
()
!=
0
{
t
.
Errorf
(
"HEAD /v1/pems body len: got %d want 0"
,
rr
.
Body
.
Len
())
}
if
rr
.
Header
()
.
Get
(
"Content-Length"
)
!=
bodyLen
{
t
.
Errorf
(
"HEAD /v1/pems Content-Length: got %s want %s"
,
rr
.
Header
()
.
Get
(
"Content-Length"
),
bodyLen
)
}
if
rr
.
Header
()
.
Get
(
"Content-Type"
)
!=
jsonContentType
{
t
.
Errorf
(
"HEAD /v1/pems Content-Type: got %s want %s"
,
rr
.
Header
()
.
Get
(
"Content-Type"
),
jsonContentType
)
}
}
func
TestAllPems405
(
t
*
testing
.
T
)
{
...
...
pkg/rest/handlers.go
View file @
09965460
...
...
@@ -266,10 +266,15 @@ func (h *pemsHndlr) allPems(
// XXX LastModified and ETag
resp
.
Header
()
.
Set
(
"Content-Type"
,
jsonContentType
)
resp
.
Header
()
.
Set
(
"Content-Length"
,
strconv
.
Itoa
(
len
(
jsonBytes
)))
n
,
err
:=
resp
.
Write
(
jsonBytes
)
if
err
!=
nil
{
h
.
log
.
Errorf
(
"%s %s: cannot write body: %v"
,
req
.
Method
,
req
.
RequestURI
,
err
)
n
:=
0
if
req
.
Method
==
http
.
MethodGet
{
n
,
err
=
resp
.
Write
(
jsonBytes
)
if
err
!=
nil
{
h
.
log
.
Errorf
(
"%s %s: cannot write body: %v"
,
req
.
Method
,
req
.
RequestURI
,
err
)
}
}
else
{
resp
.
WriteHeader
(
http
.
StatusOK
)
}
reqLog
(
h
.
log
,
req
,
now
,
http
.
StatusOK
,
n
)
}
...
...
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