2015-05-01 19:35:40 +00:00
|
|
|
package cephfs_test
|
|
|
|
|
2018-10-09 04:26:51 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/ceph/go-ceph/cephfs"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
|
|
|
func TestCreateMount(t *testing.T) {
|
2015-07-08 08:34:54 +00:00
|
|
|
mount, err := cephfs.CreateMount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
2018-10-09 04:26:51 +00:00
|
|
|
assert.True(t, mount.IsMounted())
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMountRoot(t *testing.T) {
|
2015-07-08 08:34:54 +00:00
|
|
|
mount, err := cephfs.CreateMount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
2018-10-09 04:26:51 +00:00
|
|
|
assert.True(t, mount.IsMounted())
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.ReadDefaultConfigFile()
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.Mount()
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSyncFs(t *testing.T) {
|
2015-07-08 08:34:54 +00:00
|
|
|
mount, err := cephfs.CreateMount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
2018-10-09 04:26:51 +00:00
|
|
|
assert.True(t, mount.IsMounted())
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.ReadDefaultConfigFile()
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.Mount()
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.SyncFs()
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestChangeDir(t *testing.T) {
|
2015-07-08 08:34:54 +00:00
|
|
|
mount, err := cephfs.CreateMount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
2018-10-09 04:26:51 +00:00
|
|
|
assert.True(t, mount.IsMounted())
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.ReadDefaultConfigFile()
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.Mount()
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
dir1 := mount.CurrentDir()
|
|
|
|
assert.NotNil(t, dir1)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.MakeDir("/asdf", 0755)
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.ChangeDir("/asdf")
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
dir2 := mount.CurrentDir()
|
|
|
|
assert.NotNil(t, dir2)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
assert.NotEqual(t, dir1, dir2)
|
|
|
|
assert.Equal(t, dir1, "/")
|
|
|
|
assert.Equal(t, dir2, "/asdf")
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
2018-10-09 04:26:51 +00:00
|
|
|
|
|
|
|
func TestRemoveDir(t *testing.T) {
|
|
|
|
dirname := "/one"
|
|
|
|
mount, err := cephfs.CreateMount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
|
|
|
assert.True(t, mount.IsMounted())
|
|
|
|
|
|
|
|
err = mount.ReadDefaultConfigFile()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.Mount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
dir1 := mount.CurrentDir()
|
|
|
|
assert.NotNil(t, dir1)
|
|
|
|
|
|
|
|
fmt.Printf("path: %v\n", dir1)
|
|
|
|
|
|
|
|
err = mount.MakeDir(dirname, 0755)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.SyncFs()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
files, _ := ioutil.ReadDir("./")
|
|
|
|
for _, f := range files {
|
|
|
|
fmt.Println(f.Name())
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = os.Stat(dirname)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.RemoveDir(dirname)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
_, err = os.Stat(dirname)
|
|
|
|
assert.EqualError(t, err, fmt.Sprintf("stat %s: no such file or directory", dirname))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnmountMount(t *testing.T) {
|
|
|
|
mount, err := cephfs.CreateMount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
|
|
|
assert.True(t, mount.IsMounted())
|
|
|
|
|
|
|
|
err = mount.Unmount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, mount.IsMounted())
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReleaseMount(t *testing.T) {
|
|
|
|
mount, err := cephfs.CreateMount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
|
|
|
assert.True(t, mount.IsMounted())
|
|
|
|
|
|
|
|
err = mount.Release()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Nil(t, mount.GetMount())
|
|
|
|
}
|