go-ceph/cephfs/path_test.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))
}