go-ceph/rbd/options_test.go

230 lines
7.0 KiB
Go
Raw Normal View History

package rbd
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestRbdOptions(t *testing.T) {
var i uint64
var s string
var err error
options := NewRbdImageOptions()
defer options.Destroy()
err = options.SetUint64(RbdImageOptionFormat, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionFormat, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionFormat)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionFormat)
assert.Error(t, err)
set, err := options.IsSet(RbdImageOptionFormat)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionFormat)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionFeatures, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionFeatures, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionFeatures)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionFeatures)
assert.Error(t, err)
set, err = options.IsSet(RbdImageOptionFeatures)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionFeatures)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionOrder, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionOrder, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionOrder)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionOrder)
assert.Error(t, err)
set, err = options.IsSet(RbdImageOptionOrder)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionOrder)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionStripeUnit, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionStripeUnit, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionStripeUnit)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionStripeUnit)
assert.Error(t, err)
set, err = options.IsSet(RbdImageOptionStripeUnit)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionStripeUnit)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionStripeCount, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionStripeCount, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionStripeCount)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionStripeCount)
assert.Error(t, err)
set, err = options.IsSet(RbdImageOptionStripeCount)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionStripeCount)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionJournalOrder, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionJournalOrder, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionJournalOrder)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionJournalOrder)
assert.Error(t, err)
set, err = options.IsSet(RbdImageOptionJournalOrder)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionJournalOrder)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionJournalSplayWidth, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionJournalSplayWidth, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionJournalSplayWidth)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionJournalSplayWidth)
assert.Error(t, err)
set, err = options.IsSet(RbdImageOptionJournalSplayWidth)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionJournalSplayWidth)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionJournalPool, 1)
assert.Error(t, err)
err = options.SetString(RbdImageOptionJournalPool, "journal")
assert.NoError(t, err)
_, err = options.GetUint64(RbdImageOptionJournalPool)
assert.Error(t, err)
s, err = options.GetString(RbdImageOptionJournalPool)
assert.NoError(t, err)
assert.True(t, s == "journal")
set, err = options.IsSet(RbdImageOptionJournalPool)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionJournalPool)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionFeaturesSet, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionFeaturesSet, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionFeaturesSet)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionFeaturesSet)
assert.Error(t, err)
set, err = options.IsSet(RbdImageOptionFeaturesSet)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionFeaturesSet)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionFeaturesClear, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionFeaturesClear, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionFeaturesClear)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionFeaturesClear)
assert.Error(t, err)
set, err = options.IsSet(RbdImageOptionFeaturesClear)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionFeaturesClear)
assert.NoError(t, err)
err = options.SetUint64(RbdImageOptionDataPool, 1)
assert.Error(t, err)
err = options.SetString(RbdImageOptionDataPool, "data")
assert.NoError(t, err)
_, err = options.GetUint64(RbdImageOptionDataPool)
assert.Error(t, err)
s, err = options.GetString(RbdImageOptionDataPool)
assert.NoError(t, err)
assert.True(t, s == "data")
set, err = options.IsSet(RbdImageOptionDataPool)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionDataPool)
assert.NoError(t, err)
/* introduced with Ceph Mimic, can not be tested on Luminous
err = options.SetUint64(RbdImageOptionFlatten, 1)
assert.NoError(t, err)
err = options.SetString(RbdImageOptionFlatten, "string not allowed")
assert.Error(t, err)
i, err = options.GetUint64(RbdImageOptionFlatten)
assert.NoError(t, err)
assert.True(t, i == 1)
_, err = options.GetString(RbdImageOptionFlatten)
assert.Error(t, err)
set, err = options.IsSet(RbdImageOptionFlatten)
assert.NoError(t, err)
assert.True(t, set)
err = options.Unset(RbdImageOptionFlatten)
assert.NoError(t, err)
*/
}
func TestRbdOptionsClear(t *testing.T) {
options := NewRbdImageOptions()
// set at least one option
err := options.SetUint64(RbdImageOptionFormat, 1)
assert.NoError(t, err)
empty := options.IsEmpty()
assert.False(t, empty)
options.Clear()
empty = options.IsEmpty()
assert.True(t, empty)
options.Destroy()
}
func TestInvalidRbdOption(t *testing.T) {
options := NewRbdImageOptions()
err := options.SetUint64(RbdImageOption(-1), 1)
assert.Error(t, err)
_, err = options.IsSet(RbdImageOption(-1))
assert.Error(t, err)
err = options.Unset(RbdImageOption(-1))
assert.Error(t, err)
options.Destroy()
}