mirror of
https://github.com/ceph/go-ceph
synced 2025-01-12 00:59:58 +00:00
bbf5fecf90
Continue organizing the cephfs functionality by creating new files for the most basic path management functions: MakeDir, RemoveDir, ChangeDir, CurrentDir Similarly, the dedicated test functions for those items are moved into a new file as well. Signed-off-by: John Mulligan <jmulligan@redhat.com>
63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package cephfs
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestChangeDir(t *testing.T) {
|
|
mount := fsConnect(t)
|
|
defer fsDisconnect(t, mount)
|
|
|
|
dir1 := mount.CurrentDir()
|
|
assert.NotNil(t, dir1)
|
|
|
|
err := mount.MakeDir("/asdf", 0755)
|
|
assert.NoError(t, err)
|
|
|
|
err = mount.ChangeDir("/asdf")
|
|
assert.NoError(t, err)
|
|
|
|
dir2 := mount.CurrentDir()
|
|
assert.NotNil(t, dir2)
|
|
|
|
assert.NotEqual(t, dir1, dir2)
|
|
assert.Equal(t, dir1, "/")
|
|
assert.Equal(t, dir2, "/asdf")
|
|
|
|
err = mount.ChangeDir("/")
|
|
assert.NoError(t, err)
|
|
err = mount.RemoveDir("/asdf")
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
func TestRemoveDir(t *testing.T) {
|
|
useMount(t)
|
|
|
|
dirname := "one"
|
|
localPath := path.Join(CephMountDir, dirname)
|
|
mount := fsConnect(t)
|
|
defer fsDisconnect(t, mount)
|
|
|
|
err := mount.MakeDir(dirname, 0755)
|
|
assert.NoError(t, err)
|
|
|
|
err = mount.SyncFs()
|
|
assert.NoError(t, err)
|
|
|
|
// os.Stat the actual mounted location to verify Makedir/RemoveDir
|
|
_, err = os.Stat(localPath)
|
|
assert.NoError(t, err)
|
|
|
|
err = mount.RemoveDir(dirname)
|
|
assert.NoError(t, err)
|
|
|
|
_, err = os.Stat(localPath)
|
|
assert.EqualError(t, err,
|
|
fmt.Sprintf("stat %s: no such file or directory", localPath))
|
|
}
|