Skip to content

Commit 98d69ed

Browse files
committed
tests: validate comparing errors of different packages
Signed-off-by: Niels de Vos <[email protected]>
1 parent 9085cb2 commit 98d69ed

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

internal/errors_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package internal
2+
3+
import (
4+
"errors"
5+
"testing"
6+
7+
"github.com/stretchr/testify/assert"
8+
9+
"github.com/ceph/go-ceph/cephfs"
10+
"github.com/ceph/go-ceph/rados"
11+
"github.com/ceph/go-ceph/rbd"
12+
)
13+
14+
func TestErrorCompare(t *testing.T) {
15+
t.Run("ErrNotConnected", func(t *testing.T) {
16+
err := rados.ErrNotConnected
17+
assert.True(t, errors.Is(err, cephfs.ErrNotConnected))
18+
assert.False(t, errors.Is(err, cephfs.ErrNotExist))
19+
})
20+
21+
t.Run("ErrNotExist", func(t *testing.T) {
22+
err := rbd.ErrNotExist
23+
assert.True(t, errors.Is(err, rbd.ErrNotFound))
24+
assert.True(t, errors.Is(err, cephfs.ErrNotExist))
25+
assert.False(t, errors.Is(err, cephfs.ErrNotConnected))
26+
})
27+
28+
t.Run("ErrNotFound", func(t *testing.T) {
29+
err := rbd.ErrNotFound
30+
assert.True(t, errors.Is(rbd.ErrNotFound, rados.ErrNotFound))
31+
assert.False(t, errors.Is(err, rados.ErrNotConnected))
32+
})
33+
}

0 commit comments

Comments
 (0)