rdb: disentangle and update TestImageCopy function

Update the TestImageCopy function to establish clear subsections and use
the new CreateImage and OpenImage functions.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
John Mulligan 2020-01-24 10:59:59 -05:00 committed by John Mulligan
parent 4691e0cb4c
commit bd0b8d5678
1 changed files with 102 additions and 49 deletions

View File

@ -708,76 +708,129 @@ func TestImageCopy(t *testing.T) {
ioctx, err := conn.OpenIOContext(poolname)
require.NoError(t, err)
name := GetUUID()
img, err := Create(ioctx, name, testImageSize, testImageOrder)
require.NoError(t, err)
t.Run("invalidParameters", func(t *testing.T) {
name := GetUUID()
options := NewRbdImageOptions()
defer options.Destroy()
err = options.SetUint64(RbdImageOptionOrder, uint64(testImageOrder))
assert.NoError(t, err)
err = CreateImage(ioctx, name, testImageSize, options)
require.NoError(t, err)
// img not open, should fail
err = img.Copy(nil, "")
assert.Equal(t, err, ErrImageNotOpen)
// img not open, should fail
img := GetImage(ioctx, name)
err = img.Copy(nil, "")
assert.Equal(t, err, ErrImageNotOpen)
err = img.Open()
require.NoError(t, err)
img, err := OpenImage(ioctx, name, NoSnapshot)
require.NoError(t, err)
// pass invalid parameters
err = img.Copy(nil, "")
assert.Error(t, err) // order of errors not enforced
// pass invalid parameters
err = img.Copy(nil, "")
assert.Error(t, err) // order of errors not enforced
err = img.Copy(ioctx, "")
assert.Equal(t, err, ErrNoName)
err = img.Copy(ioctx, "")
assert.Equal(t, err, ErrNoName)
err = img.Copy(nil, "duplicate")
assert.Equal(t, err, ErrNoIOContext)
err = img.Copy(nil, "duplicate")
assert.Equal(t, err, ErrNoIOContext)
err = img.Close()
assert.NoError(t, err)
err = RemoveImage(ioctx, name)
assert.NoError(t, err)
})
// try successful copying
name = GetUUID()
err = img.Copy(ioctx, name)
require.NoError(t, err)
t.Run("successfulCopy", func(t *testing.T) {
name := GetUUID()
options := NewRbdImageOptions()
defer options.Destroy()
err = options.SetUint64(RbdImageOptionOrder, uint64(testImageOrder))
assert.NoError(t, err)
err = CreateImage(ioctx, name, testImageSize, options)
require.NoError(t, err)
img2 := GetImage(ioctx, name)
err = img2.Open()
require.NoError(t, err)
img, err := OpenImage(ioctx, name, NoSnapshot)
require.NoError(t, err)
err = img2.Close()
assert.NoError(t, err)
name2 := GetUUID()
err = img.Copy(ioctx, name2)
require.NoError(t, err)
err = img2.Remove()
assert.NoError(t, err)
img2, err := OpenImage(ioctx, name2, NoSnapshot)
require.NoError(t, err)
err = img.Close()
assert.NoError(t, err)
err = img2.Close()
assert.NoError(t, err)
// test with Image as parameter
name = GetUUID()
img2, err = Create(ioctx, name, testImageSize, testImageOrder)
require.NoError(t, err)
err = img2.Remove()
assert.NoError(t, err)
err = img.Copy2(img2)
assert.Equal(t, err, ErrImageNotOpen)
err = img.Close()
assert.NoError(t, err)
})
err = img.Open()
assert.NoError(t, err)
t.Run("copy2ImageNotOpen", func(t *testing.T) {
name := GetUUID()
name2 := GetUUID()
img := GetImage(ioctx, name)
img2 := GetImage(ioctx, name2)
err = img.Copy2(img2)
assert.Equal(t, err, ErrImageNotOpen)
err = img.Copy2(img2)
assert.Equal(t, err, ErrImageNotOpen)
err = img2.Open()
require.NoError(t, err)
options := NewRbdImageOptions()
defer options.Destroy()
err = options.SetUint64(RbdImageOptionOrder, uint64(testImageOrder))
assert.NoError(t, err)
err = CreateImage(ioctx, name, testImageSize, options)
require.NoError(t, err)
img, err = OpenImage(ioctx, name, NoSnapshot)
assert.NoError(t, err)
err = img.Copy2(img2)
require.NoError(t, err)
err = img.Copy2(img2)
assert.Equal(t, err, ErrImageNotOpen)
err = img2.Close()
assert.NoError(t, err)
err = img.Close()
assert.NoError(t, err)
err = RemoveImage(ioctx, name)
assert.NoError(t, err)
})
err = img2.Remove()
assert.NoError(t, err)
t.Run("successfulCopy2", func(t *testing.T) {
name := GetUUID()
name2 := GetUUID()
err = img.Close()
assert.NoError(t, err)
options := NewRbdImageOptions()
defer options.Destroy()
err = options.SetUint64(RbdImageOptionOrder, uint64(testImageOrder))
assert.NoError(t, err)
err = CreateImage(ioctx, name, testImageSize, options)
require.NoError(t, err)
img, err := OpenImage(ioctx, name, NoSnapshot)
assert.NoError(t, err)
err = img.Remove()
assert.NoError(t, err)
err = CreateImage(ioctx, name2, testImageSize, options)
require.NoError(t, err)
img2, err := OpenImage(ioctx, name2, NoSnapshot)
assert.NoError(t, err)
err = img.Copy2(img2)
require.NoError(t, err)
err = img2.Close()
assert.NoError(t, err)
err = img2.Remove()
assert.NoError(t, err)
err = img.Close()
assert.NoError(t, err)
err = img.Remove()
assert.NoError(t, err)
})
ioctx.Destroy()
conn.DeletePool(poolname)