mirror of https://github.com/ceph/go-ceph
cephfs: consolidate error types & values in an errors.go file
Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
054ae8ddff
commit
f584aef60f
|
@ -9,36 +9,11 @@ package cephfs
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ceph/go-ceph/internal/errutil"
|
||||
"github.com/ceph/go-ceph/rados"
|
||||
)
|
||||
|
||||
// revive:disable:exported Temporarily live with stuttering
|
||||
|
||||
// CephFSError represents an error condition returned from the CephFS APIs.
|
||||
type CephFSError int
|
||||
|
||||
// revive:enable:exported
|
||||
|
||||
// Error returns the error string for the CephFSError type.
|
||||
func (e CephFSError) Error() string {
|
||||
errno, s := errutil.FormatErrno(int(e))
|
||||
if s == "" {
|
||||
return fmt.Sprintf("cephfs: ret=%d", errno)
|
||||
}
|
||||
return fmt.Sprintf("cephfs: ret=%d, %s", errno, s)
|
||||
}
|
||||
|
||||
func getError(e C.int) error {
|
||||
if e == 0 {
|
||||
return nil
|
||||
}
|
||||
return CephFSError(e)
|
||||
}
|
||||
|
||||
// MountInfo exports ceph's ceph_mount_info from libcephfs.cc
|
||||
type MountInfo struct {
|
||||
mount *C.struct_ceph_mount_info
|
||||
|
|
|
@ -256,19 +256,6 @@ func TestChown(t *testing.T) {
|
|||
|
||||
}
|
||||
|
||||
func TestCephFSError(t *testing.T) {
|
||||
err := getError(0)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = getError(-5) // IO error
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, err.Error(), "cephfs: ret=5, Input/output error")
|
||||
|
||||
err = getError(345) // no such errno
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, err.Error(), "cephfs: ret=345")
|
||||
}
|
||||
|
||||
func radosConnect(t *testing.T) *rados.Conn {
|
||||
conn, err := rados.NewConn()
|
||||
require.NoError(t, err)
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
package cephfs
|
||||
|
||||
/*
|
||||
#include <errno.h>
|
||||
*/
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/ceph/go-ceph/internal/errutil"
|
||||
)
|
||||
|
||||
// revive:disable:exported Temporarily live with stuttering
|
||||
|
||||
// CephFSError represents an error condition returned from the CephFS APIs.
|
||||
type CephFSError int
|
||||
|
||||
// revive:enable:exported
|
||||
|
||||
// Error returns the error string for the CephFSError type.
|
||||
func (e CephFSError) Error() string {
|
||||
errno, s := errutil.FormatErrno(int(e))
|
||||
if s == "" {
|
||||
return fmt.Sprintf("cephfs: ret=%d", errno)
|
||||
}
|
||||
return fmt.Sprintf("cephfs: ret=%d, %s", errno, s)
|
||||
}
|
||||
|
||||
func getError(e C.int) error {
|
||||
if e == 0 {
|
||||
return nil
|
||||
}
|
||||
return CephFSError(e)
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package cephfs
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCephFSError(t *testing.T) {
|
||||
err := getError(0)
|
||||
assert.NoError(t, err)
|
||||
|
||||
err = getError(-5) // IO error
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, err.Error(), "cephfs: ret=5, Input/output error")
|
||||
|
||||
err = getError(345) // no such errno
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, err.Error(), "cephfs: ret=345")
|
||||
}
|
Loading…
Reference in New Issue