mirror of https://github.com/ceph/go-ceph
cephfs admin: replace "command tracer" with common version from commands
Previously, this functionality was taken into commands package. Use that. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
20b3c151b3
commit
55a5732b3f
|
@ -4,7 +4,6 @@ package admin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -12,6 +11,8 @@ import (
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/ceph/go-ceph/internal/commands"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -53,49 +54,6 @@ func TestServerSentinel(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tracingCommander serves two purposes: first, it allows one to trace the
|
|
||||||
// input and output json when running the tests. It can help with actually
|
|
||||||
// debugging the tests. Second, it demonstrates the rationale for using an
|
|
||||||
// interface in FSAdmin. You can layer any sort of debugging, error injection,
|
|
||||||
// or whatnot between the FSAdmin layer and the RADOS layer.
|
|
||||||
type tracingCommander struct {
|
|
||||||
conn RadosCommander
|
|
||||||
}
|
|
||||||
|
|
||||||
func tracer(c RadosCommander) RadosCommander {
|
|
||||||
return &tracingCommander{c}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *tracingCommander) MgrCommand(buf [][]byte) ([]byte, string, error) {
|
|
||||||
fmt.Println("(MGR Command)")
|
|
||||||
for i := range buf {
|
|
||||||
fmt.Println("IN:", string(buf[i]))
|
|
||||||
}
|
|
||||||
r, s, err := t.conn.MgrCommand(buf)
|
|
||||||
fmt.Println("OUT(result):", string(r))
|
|
||||||
if s != "" {
|
|
||||||
fmt.Println("OUT(status):", s)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("OUT(error):", err.Error())
|
|
||||||
}
|
|
||||||
return r, s, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t *tracingCommander) MonCommand(buf []byte) ([]byte, string, error) {
|
|
||||||
fmt.Println("(MON Command)")
|
|
||||||
fmt.Println("IN:", string(buf))
|
|
||||||
r, s, err := t.conn.MonCommand(buf)
|
|
||||||
fmt.Println("OUT(result):", string(r))
|
|
||||||
if s != "" {
|
|
||||||
fmt.Println("OUT(status):", s)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("OUT(error):", err.Error())
|
|
||||||
}
|
|
||||||
return r, s, err
|
|
||||||
}
|
|
||||||
|
|
||||||
func getFSAdmin(t *testing.T) *FSAdmin {
|
func getFSAdmin(t *testing.T) *FSAdmin {
|
||||||
if cachedFSAdmin != nil {
|
if cachedFSAdmin != nil {
|
||||||
return cachedFSAdmin
|
return cachedFSAdmin
|
||||||
|
@ -107,7 +65,7 @@ func getFSAdmin(t *testing.T) *FSAdmin {
|
||||||
// optional tracer.
|
// optional tracer.
|
||||||
c := fsa.conn
|
c := fsa.conn
|
||||||
if debugTrace {
|
if debugTrace {
|
||||||
c = tracer(c)
|
c = commands.NewTraceCommander(c)
|
||||||
}
|
}
|
||||||
cachedFSAdmin = NewFromConn(c)
|
cachedFSAdmin = NewFromConn(c)
|
||||||
// We sleep briefly before returning in order to ensure we have a mgr map
|
// We sleep briefly before returning in order to ensure we have a mgr map
|
||||||
|
@ -163,20 +121,20 @@ func TestParseListNames(t *testing.T) {
|
||||||
func TestCheckEmptyResponseExpected(t *testing.T) {
|
func TestCheckEmptyResponseExpected(t *testing.T) {
|
||||||
R := newResponse
|
R := newResponse
|
||||||
t.Run("error", func(t *testing.T) {
|
t.Run("error", func(t *testing.T) {
|
||||||
err := R(nil, "", errors.New("bonk")).noData().End()
|
err := R(nil, "", errors.New("bonk")).NoData().End()
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
assert.Equal(t, "bonk", err.Error())
|
assert.Equal(t, "bonk", err.Error())
|
||||||
})
|
})
|
||||||
t.Run("statusSet", func(t *testing.T) {
|
t.Run("statusSet", func(t *testing.T) {
|
||||||
err := R(nil, "unexpected!", nil).noData().End()
|
err := R(nil, "unexpected!", nil).NoData().End()
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
t.Run("someJSON", func(t *testing.T) {
|
t.Run("someJSON", func(t *testing.T) {
|
||||||
err := R([]byte(`{"trouble": true}`), "", nil).noData().End()
|
err := R([]byte(`{"trouble": true}`), "", nil).NoData().End()
|
||||||
assert.Error(t, err)
|
assert.Error(t, err)
|
||||||
})
|
})
|
||||||
t.Run("ok", func(t *testing.T) {
|
t.Run("ok", func(t *testing.T) {
|
||||||
err := R([]byte{}, "", nil).noData().End()
|
err := R([]byte{}, "", nil).NoData().End()
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue