go-ceph/rados/rados_set_locator_test.go
mergify-bot a88702fb93 rados: add wrapper to set locator key on IOContext (#651)
add wrapper to set locator key on IOContext

Signed-off-by: Alexander Pücker <alexander.puecker@hetzner.com>

* mark API as PREVIEW and update docs

Signed-off-by: Alexander Pücker <alexander.puecker@hetzner.com>

* move new API call into own file to add preview build tag

Signed-off-by: Alexander Pücker <alexander.puecker@hetzner.com>

* reset locater with nil instead of a empty string

Signed-off-by: Alexander Pücker <alexander.puecker@hetzner.com>

* rename variables for naming consistency

Signed-off-by: Alexander Pücker <alexander.puecker@hetzner.com>

* update release versions for new API call

Signed-off-by: Alexander Pücker <alexander.puecker@hetzner.com>
2022-03-05 15:43:02 +00:00

51 lines
1.6 KiB
Go

//go:build ceph_preview
// +build ceph_preview
package rados
import (
"github.com/stretchr/testify/assert"
)
func (suite *RadosTestSuite) TestSetLocator() {
suite.SetupConnection()
// create normal object without locator - used later to test reset of locator
testDataNoLocator := []byte("no locator")
err := suite.ioctx.Write("default-locator", testDataNoLocator, 0)
assert.NoError(suite.T(), err)
// test create and read with different locator
testDataLocator := []byte("test data")
suite.ioctx.SetLocator("SomeOtherLocator")
err = suite.ioctx.Write("different-locator", testDataLocator, 0)
assert.NoError(suite.T(), err)
_, err = suite.ioctx.Stat("different-locator")
assert.NoError(suite.T(), err)
bytesOut := make([]byte, len(testDataLocator))
nOut, err := suite.ioctx.Read("different-locator", bytesOut, 0)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), nOut, len(testDataLocator))
assert.Equal(suite.T(), testDataLocator, bytesOut)
// test stat with wrong locator
suite.ioctx.SetLocator("SomeWrongLocator")
_, err = suite.ioctx.Stat("different-locator")
assert.Error(suite.T(), err)
_, err = suite.ioctx.Stat("default-locator")
assert.Error(suite.T(), err)
// test reset of locator and access to object without locator
suite.ioctx.SetLocator("")
_, err = suite.ioctx.Stat("default-locator")
assert.NoError(suite.T(), err)
bytesOut = make([]byte, len(testDataNoLocator))
nOut, err = suite.ioctx.Read("default-locator", bytesOut, 0)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), nOut, len(testDataNoLocator))
assert.Equal(suite.T(), testDataNoLocator, bytesOut)
}