Skip to content

Commit

Permalink
rados/striper: add some xattr file tests for the striper package
Browse files Browse the repository at this point in the history
Signed-off-by: John Mulligan <jmulligan@redhat.com>
  • Loading branch information
phlogistonjohn authored and mergify[bot] committed Aug 8, 2024
1 parent 6143ff6 commit 0606388
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rados/striper/striper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
100 changes: 100 additions & 0 deletions rados/striper/xattr_test.go
Original file line number Diff line number Diff line change
@@ -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"]))
}

0 comments on commit 0606388

Please sign in to comment.