Add unit test for rbd_trash functionality

Signed-off-by: Daniel Swarbrick <daniel.swarbrick@gmail.com>
This commit is contained in:
Daniel Swarbrick 2018-09-17 23:07:18 +02:00
parent 4a88b5da12
commit 837181cb94
No known key found for this signature in database
GPG Key ID: C346A9571DD986F5
1 changed files with 43 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"os/exec"
"sort"
"testing"
"time"
)
//Rdb feature
@ -316,3 +317,45 @@ func TestNotFound(t *testing.T) {
conn.DeletePool(poolname)
conn.Shutdown()
}
func TestTrashImage(t *testing.T) {
conn, _ := rados.NewConn()
conn.ReadDefaultConfigFile()
conn.Connect()
poolname := GetUUID()
err := conn.MakePool(poolname)
assert.NoError(t, err)
ioctx, err := conn.OpenIOContext(poolname)
assert.NoError(t, err)
name := GetUUID()
image, err := rbd.Create(ioctx, name, 1<<22, 22)
assert.NoError(t, err)
err = image.Trash(time.Hour)
assert.NoError(t, err)
trashList, err := rbd.GetTrashList(ioctx)
assert.NoError(t, err)
assert.Equal(t, len(trashList), 1, "trashList length equal")
err = rbd.TrashRestore(ioctx, trashList[0].Id, name+"_restored")
assert.NoError(t, err)
image2 := rbd.GetImage(ioctx, name+"_restored")
err = image2.Trash(time.Hour)
assert.NoError(t, err)
trashList, err = rbd.GetTrashList(ioctx)
assert.NoError(t, err)
assert.Equal(t, len(trashList), 1, "trashList length equal")
err = rbd.TrashRemove(ioctx, trashList[0].Id, false)
assert.NoError(t, err)
ioctx.Destroy()
conn.DeletePool(poolname)
conn.Shutdown()
}