Exemplo n.º 1
0
	"github.com/redforks/errors"

	. "github.com/onsi/ginkgo"
)

var _ = Describe("errors", func() {

	assertError := func(e errors.Error, msg string, causedBy errors.CausedBy) {
		Ω(e.Error()).Should(Equal(msg))
		Ω(e.CausedBy()).Should(Equal(causedBy))
	}

	Context("Wrap error", func() {

		It("New", func() {
			assertError(errors.New("foo"), "foo", errors.ByBug)
		})

		It("NewBug", func() {
			assertError(errors.NewBug(syserr.New("foo")), "foo", errors.ByBug)
		})

		It("NewRuntime", func() {
			assertError(errors.NewRuntime(syserr.New("foo")), "foo", errors.ByRuntime)
		})

		It("NewExternal", func() {
			assertError(errors.NewExternal(syserr.New("foo")), "foo", errors.ByExternal)
		})

		It("NewInput", func() {
Exemplo n.º 2
0
	})

	It("Without error", func() {
		hit := 0
		Go(func() error {
			hit++
			return nil
		})
		Ω(hit).Should(Equal(1))
		Ω(exitCodes).Should(BeEmpty())
		Ω(onError).Should(Equal(0))
	})

	It("Exit", func() {
		Go(func() error {
			return NewExitError(1)
		})
		Ω(exitCodes).Should(Equal([]int{1}))
		Ω(onAbort).Should(Equal(1))
		Ω(onError).Should(Equal(0))
	})

	It("Report error", func() {
		Go(func() error {
			return errors.New("foo")
		})
		Ω(onError).Should(Equal(1))
	})

})