generated from dogmatiq/template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror_test.go
61 lines (50 loc) · 1.17 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
package configkit_test
import (
. "github.com/dogmatiq/configkit"
"github.com/dogmatiq/configkit/internal/validation"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("type Error", func() {
Describe("func Error()", func() {
It("returns the error message", func() {
err := Error("<message>")
Expect(err.Error()).To(Equal("<message>"))
})
})
})
var _ = Describe("func Recover()", func() {
It("recovers from config related panics", func() {
err := func() (err error) {
defer Recover(&err)
validation.Panicf("<value>")
return nil
}()
Expect(err).To(Equal(Error("<value>")))
})
It("does not recover from unrelated panics", func() {
var value interface{}
func() {
defer func() {
value = recover()
}()
func() (err error) {
defer Recover(&err)
panic("<value>") // not a configkit.Error
}()
}()
Expect(value).To(Equal("<value>"))
})
It("does not panic when no panic occurs", func() {
err := func() (err error) {
defer Recover(&err)
return nil
}()
Expect(err).ShouldNot(HaveOccurred())
})
It("panics when passed a nil pointer", func() {
Expect(func() {
Recover(nil)
}).To(Panic())
})
})