2020-03-30 20:11:54 +00:00
|
|
|
package rbd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-07-24 00:19:57 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-03-30 20:11:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRBDError(t *testing.T) {
|
|
|
|
err := getError(0)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = getError(-39) // NOTEMPTY (image still has a snapshot)
|
|
|
|
assert.Error(t, err)
|
2020-08-10 15:04:52 +00:00
|
|
|
assert.Equal(t, err.Error(), "rbd: ret=-39, Directory not empty")
|
2020-03-30 20:11:54 +00:00
|
|
|
|
2020-08-10 14:31:57 +00:00
|
|
|
errno, ok := err.(interface{ ErrorCode() int })
|
2020-07-24 00:19:57 +00:00
|
|
|
assert.True(t, ok)
|
|
|
|
require.NotNil(t, errno)
|
2020-08-10 14:31:57 +00:00
|
|
|
assert.Equal(t, errno.ErrorCode(), -39)
|
2020-07-24 00:19:57 +00:00
|
|
|
|
2020-03-30 20:11:54 +00:00
|
|
|
err = getError(345) // no such errno
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, err.Error(), "rbd: ret=345")
|
|
|
|
}
|