Skip to content

Commit

Permalink
tests: validate comparing errors of different packages
Browse files Browse the repository at this point in the history
Signed-off-by: Niels de Vos <[email protected]>
  • Loading branch information
nixpanic committed Oct 2, 2024
1 parent 9085cb2 commit 98d69ed
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions internal/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package internal

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"

"github.com/ceph/go-ceph/cephfs"
"github.com/ceph/go-ceph/rados"
"github.com/ceph/go-ceph/rbd"
)

func TestErrorCompare(t *testing.T) {
t.Run("ErrNotConnected", func(t *testing.T) {
err := rados.ErrNotConnected
assert.True(t, errors.Is(err, cephfs.ErrNotConnected))
assert.False(t, errors.Is(err, cephfs.ErrNotExist))
})

t.Run("ErrNotExist", func(t *testing.T) {
err := rbd.ErrNotExist
assert.True(t, errors.Is(err, rbd.ErrNotFound))
assert.True(t, errors.Is(err, cephfs.ErrNotExist))
assert.False(t, errors.Is(err, cephfs.ErrNotConnected))
})

t.Run("ErrNotFound", func(t *testing.T) {
err := rbd.ErrNotFound
assert.True(t, errors.Is(rbd.ErrNotFound, rados.ErrNotFound))
assert.False(t, errors.Is(err, rados.ErrNotConnected))
})
}

0 comments on commit 98d69ed

Please sign in to comment.