summaryrefslogtreecommitdiff
path: root/pkg/errorhandling/errorhandling_test.go
diff options
context:
space:
mode:
authorSascha Grunert <sgrunert@redhat.com>2022-06-30 16:47:21 +0200
committerSascha Grunert <sgrunert@redhat.com>2022-07-04 15:39:00 +0200
commit597de7a083c329bdaed7fc469555a4142f71bcb8 (patch)
tree5f49d85e2f273a71520dc4b391f051cb1cbf3d07 /pkg/errorhandling/errorhandling_test.go
parent3e8ab312395b32d0b43f1ac82adf53439b012893 (diff)
downloadpodman-597de7a083c329bdaed7fc469555a4142f71bcb8.tar.gz
podman-597de7a083c329bdaed7fc469555a4142f71bcb8.tar.bz2
podman-597de7a083c329bdaed7fc469555a4142f71bcb8.zip
libpod/runtime: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of the deprecated github.com/pkg/errors package. [NO NEW TESTS NEEDED] Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
Diffstat (limited to 'pkg/errorhandling/errorhandling_test.go')
-rw-r--r--pkg/errorhandling/errorhandling_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/pkg/errorhandling/errorhandling_test.go b/pkg/errorhandling/errorhandling_test.go
new file mode 100644
index 000000000..ec720c5e7
--- /dev/null
+++ b/pkg/errorhandling/errorhandling_test.go
@@ -0,0 +1,53 @@
+package errorhandling
+
+import (
+ "errors"
+ "fmt"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestCause(t *testing.T) {
+ t.Parallel()
+
+ for _, tc := range []struct {
+ name string
+ err func() error
+ expectedErr error
+ }{
+ {
+ name: "nil error",
+ err: func() error { return nil },
+ expectedErr: nil,
+ },
+ {
+ name: "equal errors",
+ err: func() error { return errors.New("foo") },
+ expectedErr: errors.New("foo"),
+ },
+ {
+ name: "wrapped error",
+ err: func() error { return fmt.Errorf("baz: %w", fmt.Errorf("bar: %w", errors.New("foo"))) },
+ expectedErr: errors.New("foo"),
+ },
+ {
+ name: "max depth reached",
+ err: func() error {
+ err := errors.New("error")
+ for i := 0; i <= 101; i++ {
+ err = fmt.Errorf("%d: %w", i, err)
+ }
+ return err
+ },
+ expectedErr: fmt.Errorf("0: %w", errors.New("error")),
+ },
+ } {
+ tc := tc
+ t.Run(tc.name, func(t *testing.T) {
+ t.Parallel()
+ err := Cause(tc.err())
+ assert.Equal(t, tc.expectedErr, err)
+ })
+ }
+}