mirror of
https://github.com/ceph/go-ceph
synced 2024-12-23 22:53:47 +00:00
6f90ce139c
revive v1.3.7 added https://github.com/mgechev/revive/pull/966 which checks for unused parameters in function literals. This caused several lint errors in go-ceph code. Signed-off-by: Manish <myathnal@redhat.com>
95 lines
2.1 KiB
Go
95 lines
2.1 KiB
Go
//go:build !nautilus
|
|
// +build !nautilus
|
|
|
|
package rbd
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestSparsifyWithProgress(t *testing.T) {
|
|
conn := radosConnect(t)
|
|
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()
|
|
err = quickCreate(ioctx, name, testImageSize, testImageOrder)
|
|
require.NoError(t, err)
|
|
defer func() { assert.NoError(t, RemoveImage(ioctx, name)) }()
|
|
|
|
t.Run("valid", func(t *testing.T) {
|
|
img, err := OpenImage(ioctx, name, NoSnapshot)
|
|
assert.NoError(t, err)
|
|
defer func() { assert.NoError(t, img.Close()) }()
|
|
|
|
cc := 0
|
|
cb := func(_, total uint64, v interface{}) int {
|
|
cc++
|
|
val := v.(int)
|
|
assert.Equal(t, 0, val)
|
|
assert.Equal(t, uint64(1), total)
|
|
return 0
|
|
}
|
|
|
|
err = img.SparsifyWithProgress(4096, cb, 0)
|
|
assert.NoError(t, err)
|
|
assert.GreaterOrEqual(t, cc, 1)
|
|
})
|
|
|
|
t.Run("negativeReturnValue", func(t *testing.T) {
|
|
img, err := OpenImage(ioctx, name, NoSnapshot)
|
|
assert.NoError(t, err)
|
|
defer func() { assert.NoError(t, img.Close()) }()
|
|
|
|
cc := 0
|
|
cb := func(_, total uint64, v interface{}) int {
|
|
cc++
|
|
val := v.(int)
|
|
assert.Equal(t, 0, val)
|
|
assert.Equal(t, uint64(1), total)
|
|
return -1
|
|
}
|
|
|
|
err = img.SparsifyWithProgress(4096, cb, 0)
|
|
assert.Error(t, err)
|
|
})
|
|
|
|
t.Run("closedImage", func(t *testing.T) {
|
|
img, err := OpenImage(ioctx, name, NoSnapshot)
|
|
assert.NoError(t, err)
|
|
assert.NoError(t, img.Close())
|
|
|
|
cc := 0
|
|
cb := func(_, total uint64, v interface{}) int {
|
|
cc++
|
|
val := v.(int)
|
|
assert.Equal(t, 0, val)
|
|
assert.Equal(t, uint64(1), total)
|
|
return 0
|
|
}
|
|
|
|
err = img.SparsifyWithProgress(4096, cb, 0)
|
|
assert.Error(t, err)
|
|
})
|
|
|
|
t.Run("invalidValue", func(t *testing.T) {
|
|
img, err := OpenImage(ioctx, name, NoSnapshot)
|
|
assert.NoError(t, err)
|
|
defer func() { assert.NoError(t, img.Close()) }()
|
|
|
|
err = img.SparsifyWithProgress(4096, nil, nil)
|
|
assert.Error(t, err)
|
|
})
|
|
}
|