From 0606388f9e6c5b85f7ede4e174a55c90025c2b32 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 29 Jul 2024 14:27:13 -0400 Subject: [PATCH] rados/striper: add some xattr file tests for the striper package Signed-off-by: John Mulligan --- rados/striper/striper_test.go | 4 +- rados/striper/xattr_test.go | 100 ++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 rados/striper/xattr_test.go diff --git a/rados/striper/striper_test.go b/rados/striper/striper_test.go index 924828c..1f16f4a 100644 --- a/rados/striper/striper_test.go +++ b/rados/striper/striper_test.go @@ -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() } diff --git a/rados/striper/xattr_test.go b/rados/striper/xattr_test.go new file mode 100644 index 0000000..721a24f --- /dev/null +++ b/rados/striper/xattr_test.go @@ -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"])) +}