-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patherror_test.go
107 lines (89 loc) · 2.4 KB
/
error_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
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 orm_test
import (
"fmt"
"github.com/phogolabs/orm"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("NotFoundError", func() {
It("returns a not found error", func() {
errx := &orm.NotFoundError{}
Expect(errx.Error()).To(Equal("orm: not found"))
})
Describe("IsNotFound", func() {
It("returns true", func() {
errx := &orm.NotFoundError{}
Expect(orm.IsNotFound(errx)).To(BeTrue())
})
Context("when the error is nil", func() {
It("returns false", func() {
Expect(orm.IsNotFound(nil)).To(BeFalse())
})
})
})
Describe("MaskNotFound", func() {
It("masks the error", func() {
Expect(orm.MaskNotFound(&orm.NotFoundError{})).To(BeNil())
})
It("masks the error", func() {
Expect(orm.MaskNotFound(fmt.Errorf("oh no"))).To(MatchError("oh no"))
})
})
})
var _ = Describe("NotSingularError", func() {
It("returns a not singular error", func() {
errx := &orm.NotSingularError{}
Expect(errx.Error()).To(Equal("orm: not singular"))
})
Describe("IsNotSingular", func() {
It("returns true", func() {
errx := &orm.NotSingularError{}
Expect(orm.IsNotSingular(errx)).To(BeTrue())
})
Context("when the error is nil", func() {
It("returns false", func() {
Expect(orm.IsNotSingular(nil)).To(BeFalse())
})
})
})
})
var _ = Describe("NotLoadedError", func() {
It("returns a not loaded error", func() {
errx := &orm.NotLoadedError{}
Expect(errx.Error()).To(Equal("orm: edge was not loaded"))
})
Describe("IsNotLoaded", func() {
It("returns true", func() {
errx := &orm.NotLoadedError{}
Expect(orm.IsNotLoaded(errx)).To(BeTrue())
})
Context("when the error is nil", func() {
It("returns false", func() {
Expect(orm.IsNotLoaded(nil)).To(BeFalse())
})
})
})
})
var _ = Describe("ConstraintError", func() {
It("returns a constraint error", func() {
errx := &orm.ConstraintError{}
Expect(errx.Error()).To(Equal("orm: constraint violation"))
})
Describe("UnWrap", func() {
It("returns the wrapped error", func() {
errx := &orm.ConstraintError{}
Expect(errx.Unwrap()).To(BeNil())
})
})
Describe("IsConstraintViolation", func() {
It("returns true", func() {
errx := &orm.ConstraintError{}
Expect(orm.IsConstraintViolation(errx)).To(BeTrue())
})
Context("when the error is nil", func() {
It("returns false", func() {
Expect(orm.IsConstraintViolation(nil)).To(BeFalse())
})
})
})
})