File: abort_test.go

package info (click to toggle)
golang-github-onsi-ginkgo-v2 2.15.0-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 4,112 kB
  • sloc: javascript: 59; sh: 14; makefile: 7
file content (91 lines) | stat: -rw-r--r-- 2,167 bytes parent folder | download | duplicates (2)
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
package command_test

import (
	"fmt"

	. "github.com/onsi/ginkgo/v2"
	. "github.com/onsi/gomega"

	"github.com/onsi/ginkgo/v2/ginkgo/command"
)

var _ = Describe("Abort", func() {
	It("panics when called", func() {
		details := command.AbortDetails{
			ExitCode:  1,
			Error:     fmt.Errorf("boom"),
			EmitUsage: true,
		}
		Ω(func() {
			command.Abort(details)
		}).Should(PanicWith(details))
	})

	Describe("AbortWith", func() {
		It("aborts with a formatted error", func() {
			Ω(func() {
				command.AbortWith("boom %d %s", 17, "bam!")
			}).Should(PanicWith(command.AbortDetails{
				ExitCode:  1,
				Error:     fmt.Errorf("boom 17 bam!"),
				EmitUsage: false,
			}))
		})
	})

	Describe("AbortWithUsage", func() {
		It("aborts with a formatted error and sets usage to true", func() {
			Ω(func() {
				command.AbortWithUsage("boom %d %s", 17, "bam!")
			}).Should(PanicWith(command.AbortDetails{
				ExitCode:  1,
				Error:     fmt.Errorf("boom 17 bam!"),
				EmitUsage: true,
			}))
		})
	})

	Describe("AbortIfError", func() {
		Context("with a nil error", func() {
			It("does not abort", func() {
				Ω(func() {
					command.AbortIfError("boom boom?", nil)
				}).ShouldNot(Panic())
			})
		})

		Context("with a non-nil error", func() {
			It("does aborts, tacking on the message", func() {
				Ω(func() {
					command.AbortIfError("boom boom?", fmt.Errorf("kaboom!"))
				}).Should(PanicWith(command.AbortDetails{
					ExitCode:  1,
					Error:     fmt.Errorf("boom boom?\nkaboom!"),
					EmitUsage: false,
				}))
			})
		})
	})

	Describe("AbortIfErrors", func() {
		Context("with an empty errors", func() {
			It("does not abort", func() {
				Ω(func() {
					command.AbortIfErrors("boom boom?", []error{})
				}).ShouldNot(Panic())
			})
		})

		Context("with non-nil errors", func() {
			It("does aborts, tacking on the messages", func() {
				Ω(func() {
					command.AbortIfErrors("boom boom?", []error{fmt.Errorf("kaboom!\n"), fmt.Errorf("kababoom!!\n")})
				}).Should(PanicWith(command.AbortDetails{
					ExitCode:  1,
					Error:     fmt.Errorf("boom boom?\nkaboom!\nkababoom!!\n"),
					EmitUsage: false,
				}))
			})
		})
	})
})