rbd/features: add test for Image.GetFeatures()

Signed-off-by: Niels de Vos <ndevos@redhat.com>
This commit is contained in:
Niels de Vos 2020-02-19 13:29:14 +01:00 committed by John Mulligan
parent 8b58ab92c4
commit 20031cf70f
1 changed files with 52 additions and 0 deletions

52
rbd/features_test.go Normal file
View File

@ -0,0 +1,52 @@
package rbd
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetFeatures(t *testing.T) {
conn := radosConnect(t)
require.NotNil(t, conn)
defer conn.Shutdown()
poolname := GetUUID()
err := conn.MakePool(poolname)
require.NoError(t, err)
defer conn.DeletePool(poolname)
ioctx, err := conn.OpenIOContext(poolname)
require.NoError(t, err)
defer ioctx.Destroy()
name := GetUUID()
options := NewRbdImageOptions()
err = options.SetUint64(RbdImageOptionFeatures, FeatureLayering|FeatureStripingV2)
require.NoError(t, err)
// FeatureStripingV2 only works with additional arguments
err = options.SetUint64(RbdImageOptionStripeUnit, 1024*1024)
require.NoError(t, err)
err = options.SetUint64(RbdImageOptionStripeCount, 4)
require.NoError(t, err)
err = CreateImage(ioctx, name, 16*1024*1024, options)
require.NoError(t, err)
defer func() { assert.NoError(t, RemoveImage(ioctx, name)) }()
image, err := OpenImageReadOnly(ioctx, name, NoSnapshot)
assert.NoError(t, err)
defer func() { assert.NoError(t, image.Close()) }()
features, err := image.GetFeatures()
assert.NoError(t, err)
t.Run("compareBits", func(t *testing.T) {
hasLayering := (features & FeatureLayering) == FeatureLayering
hasStripingV2 := (features & FeatureStripingV2) == FeatureStripingV2
assert.True(t, hasLayering, "FeatureLayering is not set")
assert.True(t, hasStripingV2, "FeatureStripingV2 is not set")
})
}