rados/striper: add some xattr file tests for the striper package

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2024-07-29 14:27:13 -04:00 committed by mergify[bot]
parent 6143ff682d
commit 0606388f9e
2 changed files with 102 additions and 2 deletions

View File

@ -98,8 +98,8 @@ func (suite *StriperTestSuite) TestNewStriperWithLayout() {
ioctx := suite.defaultContext()
defer ioctx.Destroy()
p := StriperLayout{65536, 16, 8388608}
striper, err := NewWithLayout(ioctx, p)
l := Layout{65536, 16, 8388608}
striper, err := NewWithLayout(ioctx, l)
assert.NoError(suite.T(), err)
striper.Destroy()
}

100
rados/striper/xattr_test.go Normal file
View File

@ -0,0 +1,100 @@
//go:build ceph_preview
package striper
import (
"github.com/stretchr/testify/require"
)
func (suite *StriperTestSuite) TestSetGetXattr() {
ioctx := suite.defaultContext()
defer ioctx.Destroy()
striper, err := New(ioctx)
require.NoError(suite.T(), err)
defer striper.Destroy()
name := "TestSetGetXattr"
err = striper.Write(name, []byte("foo"), 0)
require.NoError(suite.T(), err)
xname := "foo.bar"
err = striper.SetXattr(name, xname, []byte("razzmatazz"))
require.NoError(suite.T(), err)
buf := make([]byte, 32)
size, err := striper.GetXattr(name, xname, buf)
require.NoError(suite.T(), err)
require.Equal(suite.T(), 10, size)
require.Equal(suite.T(), "razzmatazz", string(buf[:size]))
size, err = striper.GetXattr(name, "nope.nope.nope", buf)
require.Error(suite.T(), err)
require.Equal(suite.T(), -61, err.(radosStriperError).ErrorCode())
}
func (suite *StriperTestSuite) TestRmXattr() {
ioctx := suite.defaultContext()
defer ioctx.Destroy()
striper, err := New(ioctx)
require.NoError(suite.T(), err)
defer striper.Destroy()
name := "TestRmXattr"
err = striper.Write(name, []byte("foo"), 0)
require.NoError(suite.T(), err)
xname := "foo.bar"
err = striper.SetXattr(name, xname, []byte("razzmatazz"))
require.NoError(suite.T(), err)
buf := make([]byte, 32)
size, err := striper.GetXattr(name, xname, buf)
require.NoError(suite.T(), err)
require.Equal(suite.T(), 10, size)
require.Equal(suite.T(), "razzmatazz", string(buf[:size]))
err = striper.RmXattr(name, xname)
require.NoError(suite.T(), err)
size, err = striper.GetXattr(name, xname, buf)
require.Error(suite.T(), err)
require.Equal(suite.T(), -61, err.(radosStriperError).ErrorCode())
}
func (suite *StriperTestSuite) TestListXattrs() {
ioctx := suite.defaultContext()
defer ioctx.Destroy()
striper, err := New(ioctx)
require.NoError(suite.T(), err)
defer striper.Destroy()
name := "TestListXattrs"
err = striper.Write(name, []byte("foo"), 0)
require.NoError(suite.T(), err)
err = striper.SetXattr(name, "foo.bar", []byte("razzmatazz"))
require.NoError(suite.T(), err)
err = striper.SetXattr(name, "foo.baz", []byte("razzle"))
require.NoError(suite.T(), err)
err = striper.SetXattr(name, "foo.zap", []byte("dazzle"))
require.NoError(suite.T(), err)
xm, err := striper.ListXattrs(name)
require.NoError(suite.T(), err)
require.Len(suite.T(), xm, 3)
require.Equal(suite.T(), "razzmatazz", string(xm["foo.bar"]))
require.Equal(suite.T(), "razzle", string(xm["foo.baz"]))
require.Equal(suite.T(), "dazzle", string(xm["foo.zap"]))
err = striper.RmXattr(name, "foo.bar")
require.NoError(suite.T(), err)
xm, err = striper.ListXattrs(name)
require.NoError(suite.T(), err)
require.Len(suite.T(), xm, 2)
require.Equal(suite.T(), "razzle", string(xm["foo.baz"]))
require.Equal(suite.T(), "dazzle", string(xm["foo.zap"]))
}