mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-18 14:54:19 +01:00
Merge pull request #69 from BetaXOi/output-qmp-err
qmp: Output error detail when execute QMP command failed
This commit is contained in:
@@ -1403,3 +1403,86 @@ func TestExecuteBalloon(t *testing.T) {
|
||||
q.Shutdown()
|
||||
<-disconnectedCh
|
||||
}
|
||||
|
||||
func TestErrorDesc(t *testing.T) {
|
||||
errDesc := "Somthing err messages"
|
||||
errData := map[string]string{
|
||||
"class": "GenericError",
|
||||
"desc": errDesc,
|
||||
}
|
||||
|
||||
connectedCh := make(chan *QMPVersion)
|
||||
disconnectedCh := make(chan struct{})
|
||||
buf := newQMPTestCommandBuffer(t)
|
||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||
checkVersion(t, connectedCh)
|
||||
|
||||
desc, err := q.errorDesc(errData)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error '%v'", err)
|
||||
}
|
||||
if desc != errDesc {
|
||||
t.Fatalf("expected '%v'\n got '%v'", errDesc, desc)
|
||||
}
|
||||
|
||||
q.Shutdown()
|
||||
<-disconnectedCh
|
||||
}
|
||||
|
||||
func TestExecCommandFailed(t *testing.T) {
|
||||
errDesc := "unable to map backing store for guest RAM: Cannot allocate memory"
|
||||
errData := map[string]string{
|
||||
"class": "GenericError",
|
||||
"desc": errDesc,
|
||||
}
|
||||
|
||||
connectedCh := make(chan *QMPVersion)
|
||||
disconnectedCh := make(chan struct{})
|
||||
buf := newQMPTestCommandBuffer(t)
|
||||
buf.AddCommand("object-add", nil, "error", errData)
|
||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||
checkVersion(t, connectedCh)
|
||||
|
||||
_, err := q.executeCommandWithResponse(context.Background(), "object-add", nil, nil, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error but got nil")
|
||||
}
|
||||
|
||||
expectedString := "QMP command failed: " + errDesc
|
||||
if err.Error() != expectedString {
|
||||
t.Fatalf("expected '%v' but got '%v'", expectedString, err)
|
||||
}
|
||||
|
||||
q.Shutdown()
|
||||
<-disconnectedCh
|
||||
}
|
||||
|
||||
func TestExecCommandFailedWithInnerError(t *testing.T) {
|
||||
errData := map[string]string{
|
||||
"class": "GenericError",
|
||||
"descFieldInvalid": "Invalid",
|
||||
}
|
||||
|
||||
connectedCh := make(chan *QMPVersion)
|
||||
disconnectedCh := make(chan struct{})
|
||||
buf := newQMPTestCommandBuffer(t)
|
||||
buf.AddCommand("object-add", nil, "error", errData)
|
||||
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||
checkVersion(t, connectedCh)
|
||||
|
||||
_, err := q.executeCommandWithResponse(context.Background(), "object-add", nil, nil, nil)
|
||||
if err == nil {
|
||||
t.Fatalf("expected error but got nil")
|
||||
}
|
||||
|
||||
expectedString := "QMP command failed: "
|
||||
if err.Error() != expectedString {
|
||||
t.Fatalf("expected '%v' but got '%v'", expectedString, err)
|
||||
}
|
||||
|
||||
q.Shutdown()
|
||||
<-disconnectedCh
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user