Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
H
helm3
Project
Project
Details
Activity
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
helm3
Commits
035ba623
Commit
035ba623
authored
Mar 17, 2016
by
Matt Butcher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(httputil): add test for decoder
parent
dec2f060
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
1 deletion
+53
-1
encoder_test.go
pkg/httputil/encoder_test.go
+53
-1
No files found.
pkg/httputil/encoder_test.go
View file @
035ba623
...
...
@@ -17,6 +17,7 @@ limitations under the License.
package
httputil
import
(
"bytes"
"encoding/json"
"errors"
"io/ioutil"
...
...
@@ -72,7 +73,58 @@ func TestTextMarshal(t *testing.T) {
}
}
func
TestAcceptEncoder
(
t
*
testing
.
T
)
{
type
encDec
struct
{
Name
string
}
func
TestDefaultEncoder
(
t
*
testing
.
T
)
{
in
:=
&
encDec
{
Name
:
"Foo"
}
var
out
,
out2
encDec
fn
:=
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
if
err
:=
Decode
(
w
,
r
,
&
out
);
err
!=
nil
{
t
.
Fatalf
(
"Failed to decode data: %s"
,
err
)
}
if
out
.
Name
!=
in
.
Name
{
t
.
Fatalf
(
"Expected %q, got %q"
,
in
.
Name
,
out
.
Name
)
}
Encode
(
w
,
r
,
out
,
http
.
StatusOK
)
}
s
:=
httptest
.
NewServer
(
http
.
HandlerFunc
(
fn
))
defer
s
.
Close
()
data
,
err
:=
json
.
Marshal
(
in
)
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to marshal JSON: %s"
,
err
)
}
req
,
err
:=
http
.
NewRequest
(
"GET"
,
s
.
URL
,
bytes
.
NewBuffer
(
data
))
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
req
.
Header
.
Set
(
"content-type"
,
"application/json"
)
res
,
err
:=
http
.
DefaultClient
.
Do
(
req
)
if
err
!=
nil
{
t
.
Errorf
(
"Failed request: %s"
,
err
)
}
if
res
.
StatusCode
!=
http
.
StatusOK
{
t
.
Errorf
(
"Expected 200, got %d"
,
res
.
StatusCode
)
}
data
,
err
=
ioutil
.
ReadAll
(
res
.
Body
)
res
.
Body
.
Close
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
err
:=
json
.
Unmarshal
(
data
,
&
out2
);
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
out2
.
Name
!=
in
.
Name
{
t
.
Errorf
(
"Expected final output to have name %q, got %q"
,
in
.
Name
,
out2
.
Name
)
}
}
func
TestAcceptEncoderEncoder
(
t
*
testing
.
T
)
{
enc
:=
&
AcceptEncoder
{
DefaultEncoding
:
"application/json"
,
}
...
...
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