go-ceph/cephfs/command_test.go
John Mulligan ce64ef536a cephfs: split (mds) command functions and tests into new files
Start organizing some of the cephfs functionality into functions grouped
by files by moving the MDS command functions into a new file. Move the
tests dedicated to those functions into a new matching file too.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
2020-04-17 13:40:01 -04:00

42 lines
942 B
Go

package cephfs
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMdsCommand(t *testing.T) {
mount := fsConnect(t)
defer fsDisconnect(t, mount)
cmd := []byte(`{"prefix": "client ls"}`)
buf, info, err := mount.MdsCommand(
testMdsName,
[][]byte{cmd})
assert.NoError(t, err)
assert.NotEqual(t, "", string(buf))
assert.Equal(t, "", string(info))
assert.Contains(t, string(buf), "ceph_version")
// response should also be valid json
var j []interface{}
err = json.Unmarshal(buf, &j)
assert.NoError(t, err)
assert.GreaterOrEqual(t, len(j), 1)
}
func TestMdsCommandError(t *testing.T) {
mount := fsConnect(t)
defer fsDisconnect(t, mount)
cmd := []byte("iAMinValId~~~")
buf, info, err := mount.MdsCommand(
testMdsName,
[][]byte{cmd})
assert.Error(t, err)
assert.Equal(t, "", string(buf))
assert.NotEqual(t, "", string(info))
assert.Contains(t, string(info), "unparseable JSON")
}