cephfs/admin: Add tests for API fetching volume info

Signed-off-by: Anoop C S <anoopcs@cryptolab.net>
This commit is contained in:
Anoop C S 2023-03-15 11:37:47 +05:30 committed by mergify[bot]
parent d9b77dfca6
commit 2eb895d54f
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
//go:build !(nautilus || octopus) && ceph_preview
// +build !nautilus,!octopus,ceph_preview
package admin
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestFetchVolumeInfo(t *testing.T) {
fsa := getFSAdmin(t)
t.Run("SimpleVolume", func(t *testing.T) {
volume := "cephfs"
vinfo, err := fsa.FetchVolumeInfo(volume)
assert.NoError(t, err)
assert.NotNil(t, vinfo)
assert.Contains(t, vinfo.MonAddrs[0], "6789")
assert.Equal(t, "cephfs_data", vinfo.Pools.DataPool[0].Name)
})
t.Run("InvalidVolume", func(t *testing.T) {
volume := "blah"
var ec ErrCode
_, err := fsa.FetchVolumeInfo(volume)
assert.True(t, errors.As(err, &ec))
assert.Equal(t, -2, ec.ErrorCode())
})
t.Run("WithSubvolume", func(t *testing.T) {
volume := "altfs"
subvolname := "altfs_subvol"
err := fsa.CreateSubVolume(volume, NoGroup, subvolname, nil)
assert.NoError(t, err)
defer func() {
err := fsa.RemoveSubVolume(volume, NoGroup, subvolname)
assert.NoError(t, err)
}()
vinfo, err := fsa.FetchVolumeInfo(volume)
assert.NoError(t, err)
assert.NotNil(t, vinfo)
assert.EqualValues(t, 0, vinfo.PendingSubvolDels)
assert.Eventually(t,
func() bool {
vinfo, err := fsa.FetchVolumeInfo(volume)
if !assert.NoError(t, err) {
return false
}
return vinfo.Pools.DataPool[0].Used != 0
},
10*time.Second,
100*time.Millisecond,
"Data pool size not updated")
})
}
type ErrCode interface {
ErrorCode() int
}