From 980176b258942d7730607c82a6690ce38c537084 Mon Sep 17 00:00:00 2001 From: Peter Grant Date: Fri, 19 Feb 2016 10:51:40 -0800 Subject: [PATCH] Test cases for empty vs nil list handling --- list_test.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/list_test.go b/list_test.go index 49c018b..c1fe07e 100644 --- a/list_test.go +++ b/list_test.go @@ -51,6 +51,41 @@ func TestList(t *testing.T) { }) }) + Convey("->Send(empty list)", func() { + + Convey("should send a properly formatted empty List response", func() { + + writer := httptest.NewRecorder() + err := Send(writer, req, List([]*Object{})) + So(err, ShouldBeNil) + So(writer.Code, ShouldEqual, http.StatusOK) + + contentLength, convErr := strconv.Atoi(writer.HeaderMap.Get("Content-Length")) + So(convErr, ShouldBeNil) + So(contentLength, ShouldBeGreaterThan, 0) + So(writer.HeaderMap.Get("Content-Type"), ShouldEqual, ContentType) + + req, reqErr := testRequest(writer.Body.Bytes()) + So(reqErr, ShouldBeNil) + + responseList, parseErr := ParseList(req) + So(parseErr, ShouldBeNil) + So(len(responseList), ShouldEqual, 0) + }) + }) + + Convey("->Send(nil list)", func() { + + Convey("should fail with a 500 ISE", func() { + + writer := httptest.NewRecorder() + var list []*Object + err := Send(writer, req, List(list)) + So(err, ShouldNotBeNil) + So(writer.Code, ShouldEqual, http.StatusInternalServerError) + }) + }) + Convey("->UnmarshalJSON()", func() { Convey("should handle a data object", func() {