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 <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2021-03-12 14:49:59 -05:00 committed by mergify[bot]
parent 3b9317b608
commit df9834fc82
1 changed files with 11 additions and 20 deletions

View File

@ -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)
}