@@ -6,7 +6,6 @@ import (
6 "encoding/base64"
6 "encoding/base64"
7 "encoding/json"
7 "encoding/json"
10 "net/http"
9 "net/http"
12 "github.com/bitly/go-simplejson"
11 "github.com/bitly/go-simplejson"
@@ -215,8 +214,8 @@ var _ = Describe("Builder suite", func() {
216 Context("if the request has been completed and then modified", func() {
215 Context("if the request has been completed and then modified", func() {
217 BeforeEach(func() {
216 BeforeEach(func() {
218− _, err := b.Do()
217+ result := b.Do()
219− Expect(err).ToNot(HaveOccurred())
218+ Expect(result.Error()).ToNot(HaveOccurred())
221 b.WithMethod("POST")
220 b.WithMethod("POST")
@@ -250,25 +249,20 @@ var _ = Describe("Builder suite", func() {
251func assertSuccessfulRequest(builder func() Builder, expectedRequest testHTTPRequest) {
250func assertSuccessfulRequest(builder func() Builder, expectedRequest testHTTPRequest) {
252 Context("Do", func() {
251 Context("Do", func() {
253− var resp *http.Response
252+ var result Result
255 BeforeEach(func() {
254 BeforeEach(func() {
257− resp, err = builder().Do()
255+ result = builder().Do()
258− Expect(err).ToNot(HaveOccurred())
256+ Expect(result.Error()).ToNot(HaveOccurred())
261 It("returns a successful status", func() {
259 It("returns a successful status", func() {
262− Expect(resp.StatusCode).To(Equal(http.StatusOK))
260+ Expect(result.StatusCode()).To(Equal(http.StatusOK))
265 It("made the expected request", func() {
263 It("made the expected request", func() {
266− body, err := ioutil.ReadAll(resp.Body)
267− Expect(err).ToNot(HaveOccurred())
270 actualRequest := testHTTPRequest{}
264 actualRequest := testHTTPRequest{}
271− Expect(json.Unmarshal(body, &actualRequest)).To(Succeed())
265+ Expect(json.Unmarshal(result.Body(), &actualRequest)).To(Succeed())
273 Expect(actualRequest).To(Equal(expectedRequest))
267 Expect(actualRequest).To(Equal(expectedRequest))
@@ -278,7 +272,7 @@ func assertSuccessfulRequest(builder func() Builder, expectedRequest testHTTPReq
278 var actualRequest testHTTPRequest
272 var actualRequest testHTTPRequest
280 BeforeEach(func() {
274 BeforeEach(func() {
281− Expect(builder().UnmarshalInto(&actualRequest)).To(Succeed())
275+ Expect(builder().Do().UnmarshalInto(&actualRequest)).To(Succeed())
284 It("made the expected request", func() {
278 It("made the expected request", func() {
@@ -291,7 +285,7 @@ func assertSuccessfulRequest(builder func() Builder, expectedRequest testHTTPReq
292 BeforeEach(func() {
286 BeforeEach(func() {
293 var err error
287 var err error
294− response, err = builder().UnmarshalJSON()
288+ response, err = builder().Do().UnmarshalJSON()
295 Expect(err).ToNot(HaveOccurred())
289 Expect(err).ToNot(HaveOccurred())
@@ -328,16 +322,15 @@ func assertSuccessfulRequest(builder func() Builder, expectedRequest testHTTPReq
328func assertRequestError(builder func() Builder, errorMessage string) {
322func assertRequestError(builder func() Builder, errorMessage string) {
329 Context("Do", func() {
323 Context("Do", func() {
330 It("returns an error", func() {
324 It("returns an error", func() {
331− resp, err := builder().Do()
325+ result := builder().Do()
332− Expect(err).To(MatchError(ContainSubstring(errorMessage)))
326+ Expect(result.Error()).To(MatchError(ContainSubstring(errorMessage)))
333− Expect(resp).To(BeNil())
337 Context("UnmarshalInto", func() {
330 Context("UnmarshalInto", func() {
338 It("returns an error", func() {
331 It("returns an error", func() {
339 var actualRequest testHTTPRequest
332 var actualRequest testHTTPRequest
340− err := builder().UnmarshalInto(&actualRequest)
333+ err := builder().Do().UnmarshalInto(&actualRequest)
341 Expect(err).To(MatchError(ContainSubstring(errorMessage)))
334 Expect(err).To(MatchError(ContainSubstring(errorMessage)))
343 // Should be empty
336 // Should be empty
@@ -347,7 +340,7 @@ func assertRequestError(builder func() Builder, errorMessage string) {
348 Context("UnmarshalJSON", func() {
341 Context("UnmarshalJSON", func() {
349 It("returns an error", func() {
342 It("returns an error", func() {
350− resp, err := builder().UnmarshalJSON()
343+ resp, err := builder().Do().UnmarshalJSON()
351 Expect(err).To(MatchError(ContainSubstring(errorMessage)))
344 Expect(err).To(MatchError(ContainSubstring(errorMessage)))
352 Expect(resp).To(BeNil())
345 Expect(resp).To(BeNil())
@@ -357,16 +350,15 @@ func assertRequestError(builder func() Builder, errorMessage string) {
357func assertJSONError(builder func() Builder, errorMessage string) {
350func assertJSONError(builder func() Builder, errorMessage string) {
358 Context("Do", func() {
351 Context("Do", func() {
359 It("does not return an error", func() {
352 It("does not return an error", func() {
360− resp, err := builder().Do()
353+ result := builder().Do()
361− Expect(err).To(BeNil())
354+ Expect(result.Error()).To(BeNil())
362− Expect(resp).ToNot(BeNil())
366 Context("UnmarshalInto", func() {
358 Context("UnmarshalInto", func() {
367 It("returns an error", func() {
359 It("returns an error", func() {
368 var actualRequest testHTTPRequest
360 var actualRequest testHTTPRequest
369− err := builder().UnmarshalInto(&actualRequest)
361+ err := builder().Do().UnmarshalInto(&actualRequest)
370 Expect(err).To(MatchError(ContainSubstring(errorMessage)))
362 Expect(err).To(MatchError(ContainSubstring(errorMessage)))
372 // Should be empty
364 // Should be empty
@@ -376,7 +368,7 @@ func assertJSONError(builder func() Builder, errorMessage string) {
377 Context("UnmarshalJSON", func() {
369 Context("UnmarshalJSON", func() {
378 It("returns an error", func() {
370 It("returns an error", func() {
379− resp, err := builder().UnmarshalJSON()
371+ resp, err := builder().Do().UnmarshalJSON()
380 Expect(err).To(MatchError(ContainSubstring(errorMessage)))
372 Expect(err).To(MatchError(ContainSubstring(errorMessage)))
381 Expect(resp).To(BeNil())
373 Expect(resp).To(BeNil())