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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
package api_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/mimuret/golang-iij-dpf/pkg/api"
)
var _ = Describe("response", func() {
Context("BadResponse", func() {
var bad *api.BadResponse
Context("Error", func() {
When("Auth error", func() {
BeforeEach(func() {
bad = &api.BadResponse{
StatusCode: 400,
ErrorType: api.ErrorTypeParamaterError,
ErrorMessage: "There are invalid parameters.",
ErrorDetails: api.ErrorDetails{
{Code: "invalid", Attribute: "access_token"},
},
}
})
It("return `Auth error`", func() {
Expect(bad.Error()).Should(MatchRegexp("Auth error"))
})
})
When("request format error", func() {
BeforeEach(func() {
bad = &api.BadResponse{
StatusCode: 400,
ErrorType: api.ErrorTypeParamaterError,
ErrorMessage: "JSON parse error occurred.",
}
})
It("return `Invalid request format`", func() {
Expect(bad.Error()).Should(MatchRegexp("ErrorType: ParameterError Message: JSON parse error occurred."))
})
})
When("invalid paramaters.", func() {
BeforeEach(func() {
bad = &api.BadResponse{
StatusCode: 400,
ErrorType: api.ErrorTypeParamaterError,
ErrorMessage: "There are invalid parameters.",
ErrorDetails: api.ErrorDetails{
{Code: "invalid", Attribute: "name"},
{Code: "notfound", Attribute: "system_id"},
},
}
})
It("return `ErrorType: ParameterError with Details`", func() {
Expect(bad.Error()).Should(MatchRegexp("ErrorType: ParameterError Message: There are invalid parameters. Detail: invalid=name, notfound=system_id"))
})
})
When("NotFound", func() {
BeforeEach(func() {
bad = &api.BadResponse{
StatusCode: 404,
ErrorType: api.ErrorTypeNotFound,
ErrorMessage: "Specified resource not found.",
}
})
It("return `ErrorType: NotFound`", func() {
Expect(bad.Error()).Should(MatchRegexp("ErrorType: NotFound Message: Specified resource not found."))
})
})
When("TooManyRequests", func() {
BeforeEach(func() {
bad = &api.BadResponse{
StatusCode: 429,
ErrorType: api.ErrorTypeTooManyRequests,
ErrorMessage: "Too many requests.",
}
})
It("return `TooManyRequests`", func() {
Expect(bad.Error()).Should(MatchRegexp("ErrorType: TooManyRequests Message: Too many requests."))
})
})
When("SystemError", func() {
BeforeEach(func() {
bad = &api.BadResponse{
StatusCode: 500,
ErrorType: api.ErrorTypeSystemError,
ErrorMessage: "System error occurred.",
}
})
It("return `SystemError`", func() {
Expect(bad.Error()).Should(MatchRegexp("ErrorType: SystemError Message: System error occurred."))
})
})
When("GatewayTimeout", func() {
BeforeEach(func() {
bad = &api.BadResponse{
StatusCode: 504,
ErrorType: api.ErrorTypeGatewayTimeout,
ErrorMessage: "Gateway timeout.",
}
})
It("return `GatewayTimeout`", func() {
Expect(bad.Error()).Should(MatchRegexp("ErrorType: GatewayTimeout Message: Gateway timeout."))
})
})
})
})
})
|