From df9834fc8264030018885c5f75697778cd695d48 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Fri, 12 Mar 2021 14:49:59 -0500 Subject: [PATCH] cephfs: remove uses of external mount of test fs The external mount point was mainly used for stat prior to a Stat function being part of go-ceph's cephfs package. Now that we have Statx, we can replace the need for the external mount and os.Stat. Signed-off-by: John Mulligan --- cephfs/permissions_test.go | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/cephfs/permissions_test.go b/cephfs/permissions_test.go index 2c90d8c..be16811 100644 --- a/cephfs/permissions_test.go +++ b/cephfs/permissions_test.go @@ -1,9 +1,6 @@ package cephfs import ( - "os" - "path" - "syscall" "testing" "github.com/stretchr/testify/assert" @@ -11,8 +8,6 @@ import ( ) func TestChmodDir(t *testing.T) { - useMount(t) - dirname := "two" var stats_before uint32 = 0755 var stats_after uint32 = 0700 @@ -26,23 +21,20 @@ func TestChmodDir(t *testing.T) { err = mount.SyncFs() assert.NoError(t, err) - // os.Stat the actual mounted location to verify Makedir/RemoveDir - stats, err := os.Stat(path.Join(CephMountDir, dirname)) + sx, err := mount.Statx(dirname, StatxBasicStats, 0) require.NoError(t, err) - assert.Equal(t, uint32(stats.Mode().Perm()), stats_before) + assert.Equal(t, uint32(sx.Mode&0777), stats_before) err = mount.Chmod(dirname, stats_after) assert.NoError(t, err) - stats, err = os.Stat(path.Join(CephMountDir, dirname)) - assert.Equal(t, uint32(stats.Mode().Perm()), stats_after) + sx, err = mount.Statx(dirname, StatxBasicStats, 0) + require.NoError(t, err) + assert.Equal(t, uint32(sx.Mode&0777), stats_after) } -// Not cross-platform, go's os does not specifiy Sys return type func TestChown(t *testing.T) { - useMount(t) - dirname := "three" // dockerfile creates bob user account var bob uint32 = 1010 @@ -58,18 +50,17 @@ func TestChown(t *testing.T) { err = mount.SyncFs() assert.NoError(t, err) - // os.Stat the actual mounted location to verify Makedir/RemoveDir - stats, err := os.Stat(path.Join(CephMountDir, dirname)) + sx, err := mount.Statx(dirname, StatxBasicStats, 0) require.NoError(t, err) - assert.Equal(t, uint32(stats.Sys().(*syscall.Stat_t).Uid), root) - assert.Equal(t, uint32(stats.Sys().(*syscall.Stat_t).Gid), root) + assert.Equal(t, uint32(sx.Uid), root) + assert.Equal(t, uint32(sx.Gid), root) err = mount.Chown(dirname, bob, bob) assert.NoError(t, err) - stats, err = os.Stat(path.Join(CephMountDir, dirname)) + sx, err = mount.Statx(dirname, StatxBasicStats, 0) 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) + assert.Equal(t, uint32(sx.Uid), bob) + assert.Equal(t, uint32(sx.Gid), bob) }