Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(240)

Unified Diff: http/client_test.go

Issue 97870044: Added json encoded for ServerErrors
Patch Set: Added json encoded for ServerErrors Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « http/client.go ('k') | testservices/errors.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: http/client_test.go
=== modified file 'http/client_test.go'
--- http/client_test.go 2013-10-17 23:02:16 +0000
+++ http/client_test.go 2014-05-02 16:28:31 +0000
@@ -181,3 +181,44 @@
c.Check(agent, Not(Equals), "")
c.Check(agent, Equals, gooseAgent())
}
+
+func (s *HTTPSClientTestSuite) TestProperlyFormattedJsonUnmarshalling(c *C) {
+ validJSON := `{"itemNotFound": {"message": "A Meaningful error", "code": 404}}`
+ unmarshalled, err := unmarshallError([]byte(validJSON))
+ c.Assert(err, IsNil)
+ c.Check(unmarshalled.Code, Equals, 404)
+ c.Check(unmarshalled.Title, Equals, "itemNotFound")
+ c.Check(unmarshalled.Message, Equals, "A Meaningful error")
+}
+
+func (s *HTTPSClientTestSuite) TestImproperlyFormattedJSONUnmarshalling(c *C) {
+ invalidJSON := `This string is not a valid JSON`
+ unmarshalled, err := unmarshallError([]byte(invalidJSON))
+ c.Assert(err, NotNil)
+ c.Assert(unmarshalled, IsNil)
+ c.Check(err, ErrorMatches, "invalid character 'T' looking for beginning of value")
+}
+
+func (s *HTTPSClientTestSuite) TestJSONMissingCodeUnmarshalling(c *C) {
+ missingCodeJSON := `{"itemNotFound": {"message": "A Meaningful error"}}`
+ unmarshalled, err := unmarshallError([]byte(missingCodeJSON))
+ c.Assert(err, NotNil)
+ c.Assert(unmarshalled, IsNil)
+ c.Check(err, ErrorMatches, `Unparsable json error body: "{\\"itemNotFound\\": {\\"message\\": \\"A Meaningful error\\"}}"`)
+}
+
+func (s *HTTPSClientTestSuite) TestJSONMissingMessageUnmarshalling(c *C) {
+ missingMessageJSON := `{"itemNotFound": {"code": 404}}`
+ unmarshalled, err := unmarshallError([]byte(missingMessageJSON))
+ c.Assert(err, NotNil)
+ c.Assert(unmarshalled, IsNil)
+ c.Check(err, ErrorMatches, `Unparsable json error body: "{\\"itemNotFound\\": {\\"code\\": 404}}"`)
+}
+
+func (s *HTTPSClientTestSuite) TestBrokenBodyJSONUnmarshalling(c *C) {
+ invalidBodyJSON := `{"itemNotFound": {}}`
+ unmarshalled, err := unmarshallError([]byte(invalidBodyJSON))
+ c.Assert(err, NotNil)
+ c.Assert(unmarshalled, IsNil)
+ c.Check(err, ErrorMatches, `Unparsable json error body: \"{\\\"itemNotFound\\\": {}}\"`)
+}
« no previous file with comments | « http/client.go ('k') | testservices/errors.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b