Ejemplo n.º 1
0
	BeforeEach(func() {
		reset.Enable()
	})

	AfterEach(func() {
		reset.Disable()
	})

	It("Context not nil", func() {
		called := 0
		ctx := context.WithValue(context.Background(), "foo", 1)

		errors.SetHandler(func(actx context.Context, err interface{}) {
			called++
			Ω(err).Should(Equal(3))
			Ω(actx).Should(Equal(ctx))
		})

		errors.Handle(ctx, 3)
		Ω(called).Should(Equal(1))
	})

	It("Context is nil", func() {
		called := 0
		errors.SetHandler(func(ctx context.Context, err interface{}) {
			called++
			Ω(ctx).Should(Equal(context.Background()))
		})

		errors.Handle(nil, 2)
Ejemplo n.º 2
0
	)

	BeforeEach(func() {
		exitCodes = nil
		hal.Exit = func(n int) {
			exitCodes = append(exitCodes, n)
		}
		reset.Enable()

		onAbort, onError = 0, 0
		life.RegisterHook("log", 0, life.OnAbort, func() {
			onAbort++
		})

		errors.SetHandler(func(_ context.Context, err interface{}) {
			onError++
		})
	})

	AfterEach(func() {
		reset.Disable()
		hal.Exit = os.Exit
		errors.SetHandler(nil)
	})

	It("Without error", func() {
		hit := 0
		Go(func() error {
			hit++
			return nil
		})