mirror of https://github.com/ceph/go-ceph
rbd: add error checking in RemoveImage()
Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
parent
9e7a1c444f
commit
3fc893bc0f
|
@ -1216,6 +1216,13 @@ func CreateImage(ioctx *rados.IOContext, name string, size uint64, rio *ImageOpt
|
|||
// Implements:
|
||||
// int rbd_remove(rados_ioctx_t io, const char *name);
|
||||
func RemoveImage(ioctx *rados.IOContext, name string) error {
|
||||
if ioctx == nil {
|
||||
return ErrNoIOContext
|
||||
}
|
||||
if name == "" {
|
||||
return ErrNoName
|
||||
}
|
||||
|
||||
c_name := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(c_name))
|
||||
return getError(C.rbd_remove(cephIoctx(ioctx), c_name))
|
||||
|
|
|
@ -1300,6 +1300,12 @@ func TestRemoveImage(t *testing.T) {
|
|||
ioctx, err := conn.OpenIOContext(poolname)
|
||||
require.NoError(t, err)
|
||||
|
||||
// pass invalid parameters
|
||||
err = RemoveImage(nil, "some-name")
|
||||
require.Error(t, err)
|
||||
err = RemoveImage(ioctx, "")
|
||||
require.Error(t, err)
|
||||
|
||||
// trying to remove a non-existent image is an error
|
||||
err = RemoveImage(ioctx, "bananarama")
|
||||
require.Error(t, err)
|
||||
|
|
Loading…
Reference in New Issue