-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors_new_test.go
More file actions
68 lines (63 loc) · 1.51 KB
/
errors_new_test.go
File metadata and controls
68 lines (63 loc) · 1.51 KB
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
// Copyright (c) 2023 Benjamin Borbe All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package errors_test
import (
"context"
stderrors "errors"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/bborbe/errors"
)
var _ = Describe("Errors", func() {
var ctx context.Context
BeforeEach(func() {
ctx = context.Background()
})
Context("Wrap", func() {
It("returns an error", func() {
err := errors.Wrap(ctx, errors.New(ctx, "banana"), "failed")
Expect(err).NotTo(BeNil())
})
It("returns nil for nil error", func() {
err := errors.Wrap(ctx, nil, "failed")
Expect(err).To(BeNil())
})
})
Context("Wrapf", func() {
It("returns an error", func() {
err := errors.Wrapf(ctx, errors.New(ctx, "banana"), "failed")
Expect(err).NotTo(BeNil())
})
It("returns nil for nil error", func() {
err := errors.Wrapf(ctx, nil, "failed")
Expect(err).To(BeNil())
})
})
Context("errors.Is", func() {
var err error
var target error
var is bool
JustBeforeEach(func() {
is = stderrors.Is(err, target)
})
Context("same", func() {
BeforeEach(func() {
err = context.Canceled
target = context.Canceled
})
It("returns true", func() {
Expect(is).To(BeTrue())
})
})
Context("wrapped", func() {
BeforeEach(func() {
err = errors.Wrapf(ctx, context.Canceled, "banana")
target = context.Canceled
})
It("returns true", func() {
Expect(is).To(BeTrue())
})
})
})
})