2019-12-12 20:00:51 +00:00
|
|
|
package cephfs
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2018-10-09 04:26:51 +00:00
|
|
|
import (
|
2020-01-28 18:09:29 +00:00
|
|
|
"encoding/json"
|
2018-10-09 04:26:51 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2020-03-19 21:38:42 +00:00
|
|
|
"path"
|
2018-10-10 22:06:47 +00:00
|
|
|
"syscall"
|
2018-10-09 04:26:51 +00:00
|
|
|
"testing"
|
2019-12-20 12:51:53 +00:00
|
|
|
"time"
|
2019-12-05 16:53:41 +00:00
|
|
|
|
2019-12-18 22:28:06 +00:00
|
|
|
"github.com/ceph/go-ceph/rados"
|
|
|
|
|
2019-12-05 16:53:41 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2018-10-09 04:26:51 +00:00
|
|
|
)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2018-10-10 22:06:47 +00:00
|
|
|
var (
|
2020-03-19 21:38:42 +00:00
|
|
|
CephMountDir = "/tmp/ceph/mds/mnt/"
|
|
|
|
requireCephMount = false
|
2020-03-23 18:41:05 +00:00
|
|
|
testMdsName = "Z"
|
2018-10-10 22:06:47 +00:00
|
|
|
)
|
|
|
|
|
2020-03-19 21:38:42 +00:00
|
|
|
func init() {
|
|
|
|
mdir := os.Getenv("GO_CEPH_TEST_MOUNT_DIR")
|
|
|
|
if mdir != "" {
|
|
|
|
CephMountDir = mdir
|
|
|
|
}
|
|
|
|
reqMount := os.Getenv("GO_CEPH_TEST_REQUIRE_MOUNT")
|
|
|
|
if reqMount == "yes" || reqMount == "true" {
|
|
|
|
requireCephMount = true
|
|
|
|
}
|
2020-03-23 18:41:05 +00:00
|
|
|
mdsName := os.Getenv("GO_CEPH_TEST_MDS_NAME")
|
|
|
|
if mdsName != "" {
|
|
|
|
testMdsName = mdsName
|
|
|
|
}
|
2020-03-19 21:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func useMount(t *testing.T) {
|
|
|
|
fail := func(m string) {
|
|
|
|
if requireCephMount {
|
|
|
|
t.Fatalf("cephfs mount required: %s %s", CephMountDir, m)
|
|
|
|
} else {
|
|
|
|
t.Skipf("cephfs mount needed: %s %s", CephMountDir, m)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
s, err := os.Stat(CephMountDir)
|
|
|
|
if err != nil || !s.IsDir() {
|
|
|
|
fail("missing or not a directory")
|
|
|
|
}
|
|
|
|
|
|
|
|
if us, ok := s.Sys().(*syscall.Stat_t); ok {
|
|
|
|
ps, err := os.Stat(path.Dir(path.Clean(CephMountDir)))
|
|
|
|
if err != nil {
|
|
|
|
fail("missing parent directory (race condition?)")
|
|
|
|
}
|
|
|
|
if ps.Sys().(*syscall.Stat_t).Dev == us.Dev {
|
|
|
|
fail("not a mount point")
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fail("not a unix-like file system? how did you even compile this?" +
|
|
|
|
"no, seriously please contact us or file an issue and let us know!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-01 19:35:40 +00:00
|
|
|
func TestCreateMount(t *testing.T) {
|
2019-12-12 20:00:51 +00:00
|
|
|
mount, err := CreateMount()
|
2015-07-08 08:34:54 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
2020-03-23 20:55:42 +00:00
|
|
|
assert.NoError(t, mount.Release())
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
func fsConnect(t *testing.T) *MountInfo {
|
2019-12-12 20:00:51 +00:00
|
|
|
mount, err := CreateMount()
|
2019-12-20 12:51:53 +00:00
|
|
|
require.NoError(t, err)
|
2019-12-05 16:53:41 +00:00
|
|
|
require.NotNil(t, mount)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2015-07-08 08:34:54 +00:00
|
|
|
err = mount.ReadDefaultConfigFile()
|
2019-12-20 12:51:53 +00:00
|
|
|
require.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
timeout := time.After(time.Second * 5)
|
|
|
|
ch := make(chan error)
|
|
|
|
go func(mount *MountInfo) {
|
|
|
|
ch <- mount.Mount()
|
|
|
|
}(mount)
|
|
|
|
select {
|
|
|
|
case err = <-ch:
|
|
|
|
case <-timeout:
|
|
|
|
err = fmt.Errorf("timed out waiting for connect")
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
return mount
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 21:11:12 +00:00
|
|
|
func fsDisconnect(t *testing.T, mount *MountInfo) {
|
|
|
|
assert.NoError(t, mount.Unmount())
|
|
|
|
assert.NoError(t, mount.Release())
|
|
|
|
}
|
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
func TestMountRoot(t *testing.T) {
|
2020-03-23 21:11:12 +00:00
|
|
|
mount := fsConnect(t)
|
|
|
|
fsDisconnect(t, mount)
|
2019-12-20 12:51:53 +00:00
|
|
|
}
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
func TestSyncFs(t *testing.T) {
|
|
|
|
mount := fsConnect(t)
|
2020-03-23 21:11:12 +00:00
|
|
|
defer fsDisconnect(t, mount)
|
2015-05-01 19:35:40 +00:00
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
err := mount.SyncFs()
|
2015-07-08 08:34:54 +00:00
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestChangeDir(t *testing.T) {
|
2019-12-20 12:51:53 +00:00
|
|
|
mount := fsConnect(t)
|
2020-03-23 21:11:12 +00:00
|
|
|
defer fsDisconnect(t, mount)
|
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
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
err := mount.MakeDir("/asdf", 0755)
|
2015-07-08 08:34:54 +00:00
|
|
|
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")
|
2020-03-23 20:56:55 +00:00
|
|
|
|
|
|
|
err = mount.ChangeDir("/")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
err = mount.RemoveDir("/asdf")
|
|
|
|
assert.NoError(t, err)
|
2015-05-01 19:35:40 +00:00
|
|
|
}
|
2018-10-09 04:26:51 +00:00
|
|
|
|
|
|
|
func TestRemoveDir(t *testing.T) {
|
2020-03-19 21:38:42 +00:00
|
|
|
useMount(t)
|
|
|
|
|
2018-10-10 22:06:47 +00:00
|
|
|
dirname := "one"
|
2020-03-19 21:38:42 +00:00
|
|
|
localPath := path.Join(CephMountDir, dirname)
|
2019-12-20 12:51:53 +00:00
|
|
|
mount := fsConnect(t)
|
2020-03-23 21:11:12 +00:00
|
|
|
defer fsDisconnect(t, mount)
|
2018-10-09 04:26:51 +00:00
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
err := mount.MakeDir(dirname, 0755)
|
2018-10-09 04:26:51 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.SyncFs()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2018-10-10 22:06:47 +00:00
|
|
|
// os.Stat the actual mounted location to verify Makedir/RemoveDir
|
2020-03-19 21:38:42 +00:00
|
|
|
_, err = os.Stat(localPath)
|
2018-10-09 04:26:51 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.RemoveDir(dirname)
|
|
|
|
assert.NoError(t, err)
|
2018-10-10 22:06:47 +00:00
|
|
|
|
2020-03-19 21:38:42 +00:00
|
|
|
_, err = os.Stat(localPath)
|
2018-10-10 22:06:47 +00:00
|
|
|
assert.EqualError(t, err,
|
2020-03-19 21:38:42 +00:00
|
|
|
fmt.Sprintf("stat %s: no such file or directory", localPath))
|
2018-10-09 04:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnmountMount(t *testing.T) {
|
2019-12-20 12:51:53 +00:00
|
|
|
t.Run("neverMounted", func(t *testing.T) {
|
|
|
|
mount, err := CreateMount()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, mount)
|
|
|
|
assert.False(t, mount.IsMounted())
|
2020-03-23 20:58:15 +00:00
|
|
|
assert.NoError(t, mount.Release())
|
2019-12-20 12:51:53 +00:00
|
|
|
})
|
|
|
|
t.Run("mountUnmount", func(t *testing.T) {
|
|
|
|
mount := fsConnect(t)
|
2020-03-23 20:58:15 +00:00
|
|
|
defer func() { assert.NoError(t, mount.Release()) }()
|
2019-12-20 12:51:53 +00:00
|
|
|
assert.True(t, mount.IsMounted())
|
|
|
|
|
|
|
|
err := mount.Unmount()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.False(t, mount.IsMounted())
|
|
|
|
})
|
2018-10-09 04:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestReleaseMount(t *testing.T) {
|
2019-12-12 20:00:51 +00:00
|
|
|
mount, err := CreateMount()
|
2018-10-09 04:26:51 +00:00
|
|
|
assert.NoError(t, err)
|
2019-12-05 16:53:41 +00:00
|
|
|
require.NotNil(t, mount)
|
2018-10-09 04:26:51 +00:00
|
|
|
|
|
|
|
err = mount.Release()
|
|
|
|
assert.NoError(t, err)
|
2018-10-10 22:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestChmodDir(t *testing.T) {
|
2020-03-19 21:38:42 +00:00
|
|
|
useMount(t)
|
|
|
|
|
2018-10-10 22:06:47 +00:00
|
|
|
dirname := "two"
|
|
|
|
var stats_before uint32 = 0755
|
|
|
|
var stats_after uint32 = 0700
|
2019-12-20 12:51:53 +00:00
|
|
|
mount := fsConnect(t)
|
2020-03-23 21:11:12 +00:00
|
|
|
defer fsDisconnect(t, mount)
|
2018-10-10 22:06:47 +00:00
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
err := mount.MakeDir(dirname, stats_before)
|
2018-10-10 22:06:47 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.SyncFs()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// os.Stat the actual mounted location to verify Makedir/RemoveDir
|
2020-03-19 21:38:42 +00:00
|
|
|
stats, err := os.Stat(path.Join(CephMountDir, dirname))
|
2019-12-05 16:53:41 +00:00
|
|
|
require.NoError(t, err)
|
2018-10-10 22:06:47 +00:00
|
|
|
|
|
|
|
assert.Equal(t, uint32(stats.Mode().Perm()), stats_before)
|
|
|
|
|
|
|
|
err = mount.Chmod(dirname, stats_after)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2020-03-19 21:38:42 +00:00
|
|
|
stats, err = os.Stat(path.Join(CephMountDir, dirname))
|
|
|
|
assert.NoError(t, err)
|
2018-10-10 22:06:47 +00:00
|
|
|
assert.Equal(t, uint32(stats.Mode().Perm()), stats_after)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Not cross-platform, go's os does not specifiy Sys return type
|
|
|
|
func TestChown(t *testing.T) {
|
2020-03-19 21:38:42 +00:00
|
|
|
useMount(t)
|
|
|
|
|
2018-10-10 22:06:47 +00:00
|
|
|
dirname := "three"
|
|
|
|
// dockerfile creates bob user account
|
|
|
|
var bob uint32 = 1010
|
2019-12-12 20:17:12 +00:00
|
|
|
var root uint32
|
2018-10-10 22:06:47 +00:00
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
mount := fsConnect(t)
|
2020-03-23 21:11:12 +00:00
|
|
|
defer fsDisconnect(t, mount)
|
2018-10-10 22:06:47 +00:00
|
|
|
|
2019-12-20 12:51:53 +00:00
|
|
|
err := mount.MakeDir(dirname, 0755)
|
2018-10-10 22:06:47 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.SyncFs()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
// os.Stat the actual mounted location to verify Makedir/RemoveDir
|
2020-03-19 21:38:42 +00:00
|
|
|
stats, err := os.Stat(path.Join(CephMountDir, dirname))
|
2019-12-05 16:53:41 +00:00
|
|
|
require.NoError(t, err)
|
2018-10-10 22:06:47 +00:00
|
|
|
|
|
|
|
assert.Equal(t, uint32(stats.Sys().(*syscall.Stat_t).Uid), root)
|
|
|
|
assert.Equal(t, uint32(stats.Sys().(*syscall.Stat_t).Gid), root)
|
|
|
|
|
|
|
|
err = mount.Chown(dirname, bob, bob)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
2020-03-19 21:38:42 +00:00
|
|
|
stats, err = os.Stat(path.Join(CephMountDir, dirname))
|
2018-10-10 22:06:47 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, uint32(stats.Sys().(*syscall.Stat_t).Uid), bob)
|
|
|
|
assert.Equal(t, uint32(stats.Sys().(*syscall.Stat_t).Gid), bob)
|
|
|
|
|
2018-10-09 04:26:51 +00:00
|
|
|
}
|
2019-12-12 20:03:17 +00:00
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
2019-12-18 22:28:06 +00:00
|
|
|
|
|
|
|
func radosConnect(t *testing.T) *rados.Conn {
|
|
|
|
conn, err := rados.NewConn()
|
|
|
|
require.NoError(t, err)
|
|
|
|
err = conn.ReadDefaultConfigFile()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
timeout := time.After(time.Second * 5)
|
|
|
|
ch := make(chan error)
|
|
|
|
go func(conn *rados.Conn) {
|
|
|
|
ch <- conn.Connect()
|
|
|
|
}(conn)
|
|
|
|
select {
|
|
|
|
case err = <-ch:
|
|
|
|
case <-timeout:
|
|
|
|
err = fmt.Errorf("timed out waiting for connect")
|
|
|
|
}
|
|
|
|
require.NoError(t, err)
|
|
|
|
return conn
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCreateFromRados(t *testing.T) {
|
|
|
|
conn := radosConnect(t)
|
|
|
|
mount, err := CreateFromRados(conn)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
|
|
|
}
|
2019-12-19 20:11:50 +00:00
|
|
|
|
|
|
|
func TestCreateMountWithId(t *testing.T) {
|
2020-01-28 18:12:33 +00:00
|
|
|
mount, err := CreateMountWithId("bobolink")
|
2019-12-19 20:11:50 +00:00
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotNil(t, mount)
|
2020-03-23 20:58:15 +00:00
|
|
|
defer func() { assert.NoError(t, mount.Release()) }()
|
2019-12-19 20:11:50 +00:00
|
|
|
|
|
|
|
err = mount.ReadDefaultConfigFile()
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.Mount()
|
|
|
|
assert.NoError(t, err)
|
2020-03-23 20:58:15 +00:00
|
|
|
defer func() { assert.NoError(t, mount.Unmount()) }()
|
2020-01-28 18:12:33 +00:00
|
|
|
|
|
|
|
// verify the custom entity_id is visible in the 'session ls' output
|
|
|
|
// of mds.
|
|
|
|
cmd := []byte(`{"prefix": "session ls"}`)
|
|
|
|
buf, info, err := mount.MdsCommand(
|
2020-03-23 18:41:05 +00:00
|
|
|
testMdsName,
|
2020-01-28 18:12:33 +00:00
|
|
|
[][]byte{cmd})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, "", string(buf))
|
|
|
|
assert.Equal(t, "", string(info))
|
|
|
|
assert.Contains(t, string(buf), `"bobolink"`)
|
2019-12-19 20:11:50 +00:00
|
|
|
}
|
2020-01-28 18:09:29 +00:00
|
|
|
|
|
|
|
func TestMdsCommand(t *testing.T) {
|
|
|
|
mount := fsConnect(t)
|
2020-03-23 21:11:12 +00:00
|
|
|
defer fsDisconnect(t, mount)
|
2020-01-28 18:09:29 +00:00
|
|
|
|
|
|
|
cmd := []byte(`{"prefix": "client ls"}`)
|
|
|
|
buf, info, err := mount.MdsCommand(
|
2020-03-23 18:41:05 +00:00
|
|
|
testMdsName,
|
2020-01-28 18:09:29 +00:00
|
|
|
[][]byte{cmd})
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.NotEqual(t, "", string(buf))
|
|
|
|
assert.Equal(t, "", string(info))
|
|
|
|
assert.Contains(t, string(buf), "ceph_version")
|
|
|
|
// response should also be valid json
|
|
|
|
var j []interface{}
|
|
|
|
err = json.Unmarshal(buf, &j)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.GreaterOrEqual(t, len(j), 1)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestMdsCommandError(t *testing.T) {
|
|
|
|
mount := fsConnect(t)
|
2020-03-23 21:11:12 +00:00
|
|
|
defer fsDisconnect(t, mount)
|
2020-01-28 18:09:29 +00:00
|
|
|
|
|
|
|
cmd := []byte("iAMinValId~~~")
|
|
|
|
buf, info, err := mount.MdsCommand(
|
2020-03-23 18:41:05 +00:00
|
|
|
testMdsName,
|
2020-01-28 18:09:29 +00:00
|
|
|
[][]byte{cmd})
|
|
|
|
assert.Error(t, err)
|
|
|
|
assert.Equal(t, "", string(buf))
|
|
|
|
assert.NotEqual(t, "", string(info))
|
|
|
|
assert.Contains(t, string(info), "unparseable JSON")
|
|
|
|
}
|
2020-02-13 22:18:01 +00:00
|
|
|
|
|
|
|
func TestMountWithRoot(t *testing.T) {
|
|
|
|
bMount := fsConnect(t)
|
2020-03-23 21:11:12 +00:00
|
|
|
defer fsDisconnect(t, bMount)
|
2020-02-13 22:18:01 +00:00
|
|
|
|
|
|
|
dir1 := "/test-mount-with-root"
|
|
|
|
err := bMount.MakeDir(dir1, 0755)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer bMount.RemoveDir(dir1)
|
|
|
|
|
|
|
|
sub1 := "/i.was.here"
|
|
|
|
dir2 := dir1 + sub1
|
|
|
|
err = bMount.MakeDir(dir2, 0755)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
defer bMount.RemoveDir(dir2)
|
|
|
|
|
|
|
|
t.Run("withRoot", func(t *testing.T) {
|
|
|
|
mount, err := CreateMount()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, mount)
|
|
|
|
defer func() {
|
|
|
|
assert.NoError(t, mount.Release())
|
|
|
|
}()
|
|
|
|
|
|
|
|
err = mount.ReadDefaultConfigFile()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.MountWithRoot(dir1)
|
|
|
|
assert.NoError(t, err)
|
2020-03-23 21:11:21 +00:00
|
|
|
defer func() {
|
|
|
|
assert.NoError(t, mount.Unmount())
|
|
|
|
}()
|
2020-02-13 22:18:01 +00:00
|
|
|
|
|
|
|
err = mount.ChangeDir(sub1)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
})
|
|
|
|
t.Run("badRoot", func(t *testing.T) {
|
|
|
|
mount, err := CreateMount()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, mount)
|
|
|
|
defer func() {
|
|
|
|
assert.NoError(t, mount.Release())
|
|
|
|
}()
|
|
|
|
|
|
|
|
err = mount.ReadDefaultConfigFile()
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.MountWithRoot("/i-yam-what-i-yam")
|
|
|
|
assert.Error(t, err)
|
|
|
|
})
|
|
|
|
}
|
2020-03-04 18:44:42 +00:00
|
|
|
|
|
|
|
func TestGetSetConfigOption(t *testing.T) {
|
|
|
|
// we don't need an active connection for this, just the handle
|
|
|
|
mount, err := CreateMount()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NotNil(t, mount)
|
2020-03-23 20:58:15 +00:00
|
|
|
defer func() { assert.NoError(t, mount.Release()) }()
|
2020-03-04 18:44:42 +00:00
|
|
|
|
|
|
|
err = mount.SetConfigOption("__dne__", "value")
|
|
|
|
assert.Error(t, err)
|
|
|
|
_, err = mount.GetConfigOption("__dne__")
|
|
|
|
assert.Error(t, err)
|
|
|
|
|
|
|
|
origVal, err := mount.GetConfigOption("log_file")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
|
|
|
err = mount.SetConfigOption("log_file", "/dev/null")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
currVal, err := mount.GetConfigOption("log_file")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, "/dev/null", currVal)
|
|
|
|
|
|
|
|
err = mount.SetConfigOption("log_file", origVal)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
currVal, err = mount.GetConfigOption("log_file")
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, origVal, currVal)
|
|
|
|
}
|