-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors_as_test.go
More file actions
73 lines (68 loc) · 1.55 KB
/
errors_as_test.go
File metadata and controls
73 lines (68 loc) · 1.55 KB
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
// Copyright (c) 2024 Benjamin Borbe All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package errors_test
import (
stderrors "errors"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
liberrors "github.com/bborbe/errors"
)
var _ = Describe("As", func() {
var target error
var err error
var result bool
JustBeforeEach(func() {
result = liberrors.As(err, target)
})
Context("not matching", func() {
BeforeEach(func() {
err = stderrors.New("banana")
target = &ErrorWithMessage{}
})
It("returns be false", func() {
Expect(result).To(BeFalse())
Expect(target.Error()).To(Equal(""))
})
})
Context("matching", func() {
BeforeEach(func() {
err = ErrorWithMessage{
Message: "banana",
}
target = &ErrorWithMessage{}
})
It("returns be true", func() {
Expect(result).To(BeTrue())
Expect(target.Error()).To(Equal("banana"))
})
})
Context("matching with wrap", func() {
BeforeEach(func() {
err = ErrorWithUnwrap{
Err: ErrorWithMessage{
Message: "banana",
},
}
target = &ErrorWithMessage{}
})
It("returns be true", func() {
Expect(result).To(BeTrue())
Expect(target.Error()).To(Equal("banana"))
})
})
Context("matching with cause", func() {
BeforeEach(func() {
err = ErrorWithCause{
Err: ErrorWithMessage{
Message: "banana",
},
}
target = &ErrorWithMessage{}
})
It("returns be true", func() {
Expect(result).To(BeTrue())
Expect(target.Error()).To(Equal("banana"))
})
})
})