forked from hudl/fargo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
52 lines (48 loc) · 1.54 KB
/
errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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})
})
})
}