-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_err_test.go
55 lines (44 loc) · 1.11 KB
/
command_err_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
package cli_test
import (
"fmt"
"github.com/phogolabs/cli"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("ExitErrorCollector", func() {
It("creates a new error", func() {
err := cli.ExitErrorCollector{
fmt.Errorf("oh no"),
}
Expect(err).To(HaveLen(1))
Expect(err[0]).To(MatchError("oh no"))
})
It("formats the error", func() {
err := cli.ExitErrorCollector{
fmt.Errorf("oh no"),
fmt.Errorf("oh ye"),
}
Expect(err).To(MatchError("oh no\noh ye"))
})
})
var _ = Describe("ExitError", func() {
It("creates a new exit error", func() {
err := cli.NewExitError("oh no!", 69)
Expect(err.Error()).To(Equal("oh no!"))
Expect(err.Code()).To(Equal(69))
})
It("wraps an error", func() {
err := fmt.Errorf("oh no")
errx := cli.WrapError(err)
Expect(errx.Unwrap()).To(Equal(err))
})
Context("WithCode", func() {
It("returns a error with new code", func() {
err := cli.NewExitError("oh no", 69)
errx := err.WithCode(129)
Expect(errx).To(MatchError("oh no"))
Expect(errx.Code()).To(Equal(129))
Expect(errx.Code()).NotTo(Equal(err.Code()))
})
})
})