-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwith_code_test.go
More file actions
32 lines (26 loc) · 884 Bytes
/
with_code_test.go
File metadata and controls
32 lines (26 loc) · 884 Bytes
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
package errors_test
import (
lerrors "github.com/lab259/errors/v2"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/pkg/errors"
)
var _ = Describe("ErrorWithCode", func() {
It("should wrap a ReportableError", func() {
nerr := errors.New("test")
err := lerrors.WrapCode(nerr, "error code")
Expect(err).NotTo(BeNil())
Expect(err.Error()).To(Equal("error code: test"))
reportableErr, ok := err.(lerrors.ErrorWithCode)
Expect(ok).To(BeTrue())
Expect(reportableErr.Code()).To(Equal("error code"))
errResponse := NewMockErrorResponse()
aggErr, ok := err.(lerrors.ErrorResponseAggregator)
Expect(ok).To(BeTrue())
aggErr.AppendData(errResponse)
Expect(errResponse.Data).To(HaveKeyWithValue("code", "error code"))
errWithReason, ok := err.(lerrors.Wrapper)
Expect(ok).To(BeTrue())
Expect(errWithReason.Unwrap()).To(Equal(nerr))
})
})