mirror of
https://github.com/ceph/go-ceph
synced 2024-12-29 09:42:08 +00:00
e40744fdf6
Now we have sufficient boilerplate in our code for interacting with various types and ceph calls with similar needs we establish a new internal package, "cutil" (C utilities). Note that many of the return types are wrapped. This is due to the limits placed on us by cgo. Despite the irritating limitations Go places on "exporting" C types it still ought to help in the long run for patterns that are very common or patterns that are subtle and we want to write specific tests for. Signed-off-by: John Mulligan <jmulligan@redhat.com>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package cutil
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestCommandInput(t *testing.T) {
|
|
t.Run("newAndFree", func(t *testing.T) {
|
|
ci := NewCommandInput(
|
|
[][]byte{[]byte("foobar")},
|
|
nil)
|
|
ci.Free()
|
|
})
|
|
t.Run("cmd", func(t *testing.T) {
|
|
ci := NewCommandInput(
|
|
[][]byte{[]byte("foobar")},
|
|
nil)
|
|
defer ci.Free()
|
|
assert.Len(t, ci.cmd, 1)
|
|
assert.EqualValues(t, 1, ci.CmdLen())
|
|
assert.NotNil(t, ci.Cmd())
|
|
})
|
|
t.Run("cmd2", func(t *testing.T) {
|
|
ci := NewCommandInput(
|
|
[][]byte{[]byte("foobar"), []byte("snarf")},
|
|
nil)
|
|
defer ci.Free()
|
|
assert.Len(t, ci.cmd, 2)
|
|
assert.EqualValues(t, 2, ci.CmdLen())
|
|
assert.NotNil(t, ci.Cmd())
|
|
})
|
|
t.Run("noInBuf", func(t *testing.T) {
|
|
ci := NewCommandInput(
|
|
[][]byte{[]byte("foobar")},
|
|
nil)
|
|
defer ci.Free()
|
|
assert.EqualValues(t, 0, ci.InBufLen())
|
|
assert.Equal(t, CharPtr(nil), ci.InBuf())
|
|
})
|
|
t.Run("hasInBuf", func(t *testing.T) {
|
|
ci := NewCommandInput(
|
|
[][]byte{[]byte("foobar")},
|
|
[]byte("original oregano"))
|
|
defer ci.Free()
|
|
assert.EqualValues(t, 16, ci.InBufLen())
|
|
assert.NotEqual(t, CharPtr(nil), ci.InBuf())
|
|
})
|
|
}
|