mirror of
https://github.com/ceph/go-ceph
synced 2024-12-23 14:45:42 +00:00
ebea82dda5
This type is useful for passing disparate buffers to be read or written in a single call. Functions using this type exist in cephfs and rbd. Currently this is needed for cephfs calls. Signed-off-by: John Mulligan <jmulligan@redhat.com>
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package cutil
|
|
|
|
import (
|
|
"testing"
|
|
"unsafe"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestIovec(t *testing.T) {
|
|
t.Run("newAndFree", func(t *testing.T) {
|
|
iov := NewIovec(3)
|
|
iov.Free()
|
|
})
|
|
t.Run("setBufs", func(t *testing.T) {
|
|
b1 := []byte("foo")
|
|
b2 := []byte("barbar")
|
|
b3 := []byte("bazbazbaz")
|
|
iov := NewIovec(3)
|
|
iov.Set(0, b1)
|
|
iov.Set(1, b2)
|
|
iov.Set(2, b3)
|
|
iov.Free()
|
|
// free also unsets internal values
|
|
assert.Equal(t, unsafe.Pointer(nil), iov.cvec)
|
|
assert.Equal(t, 0, iov.length)
|
|
})
|
|
t.Run("testGetters", func(t *testing.T) {
|
|
b1 := []byte("foo")
|
|
b2 := []byte("barbar")
|
|
b3 := []byte("bazbazbaz")
|
|
b4 := []byte("zonk")
|
|
iov := NewIovec(4)
|
|
defer iov.Free()
|
|
iov.Set(0, b1)
|
|
iov.Set(1, b2)
|
|
iov.Set(2, b3)
|
|
iov.Set(3, b4)
|
|
|
|
assert.NotNil(t, iov.Pointer())
|
|
assert.Equal(t, 4, iov.Len())
|
|
})
|
|
}
|
|
|
|
func TestByteSlicesToIovec(t *testing.T) {
|
|
d := [][]byte{
|
|
[]byte("ramekin"),
|
|
[]byte("shuffleboard"),
|
|
[]byte("tranche"),
|
|
[]byte("phycobilisomes"),
|
|
}
|
|
iov := ByteSlicesToIovec(d)
|
|
defer iov.Free()
|
|
|
|
assert.NotNil(t, iov.Pointer())
|
|
assert.Equal(t, 4, iov.Len())
|
|
}
|