mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
qmp: Add tests
Test execute QMP command with error response. Signed-off-by: NingBo <ning.bo9@zte.com.cn>
This commit is contained in:
parent
f30fd1354a
commit
dab4cf1d70
@ -1363,3 +1363,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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user