forked from hudl/fargo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hudl#52 from seh/expose-http-status-code-in-errors
Expose response HTTP status code in errors
- Loading branch information
Showing
4 changed files
with
113 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package fargo | ||
|
||
// MIT Licensed (see README.md) - Copyright (c) 2013 Hudl <@Hudl> | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
"testing" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestHTTPResponseStatusCode(t *testing.T) { | ||
Convey("An nil error should have no HTTP status code", t, func() { | ||
_, present := HTTPResponseStatusCode(nil) | ||
So(present, ShouldBeFalse) | ||
}) | ||
Convey("A foreign error should have no detectable HTTP status code", t, func() { | ||
_, present := HTTPResponseStatusCode(errors.New("other")) | ||
So(present, ShouldBeFalse) | ||
}) | ||
Convey("A fargo error generated from a response from Eureka", t, func() { | ||
verify := func(err *unsuccessfulHTTPResponse) { | ||
Convey("should have the given HTTP status code", func() { | ||
code, present := HTTPResponseStatusCode(err) | ||
So(present, ShouldBeTrue) | ||
So(code, ShouldEqual, err.statusCode) | ||
Convey("should produce a message", func() { | ||
msg := err.Error() | ||
if len(err.messagePrefix) == 0 { | ||
Convey("that lacks a prefx", func() { | ||
So(msg, ShouldNotStartWith, ",") | ||
}) | ||
} else { | ||
Convey("that starts with the given prefix", func() { | ||
So(msg, ShouldStartWith, err.messagePrefix) | ||
}) | ||
} | ||
Convey("that contains the status code in decimal notation", func() { | ||
So(msg, ShouldContainSubstring, strconv.Itoa(err.statusCode)) | ||
}) | ||
}) | ||
}) | ||
} | ||
Convey("with a message prefix", func() { | ||
verify(&unsuccessfulHTTPResponse{500, "operation failed"}) | ||
}) | ||
Convey("without a message prefix", func() { | ||
verify(&unsuccessfulHTTPResponse{statusCode: 500}) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters