mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-23 14:08:31 +00:00
Add some negative test cases for qmp.go
This commit adds a couple of negative test cases for qmp.go, one which checks that failed commands return errors and the other checks that QMPStart exits gracefully when passed an invalid socket path. Signed-off-by: Mark Ryan <mark.d.ryan@intel.com>
This commit is contained in:
parent
17cacc7238
commit
ed34f61664
@ -251,6 +251,22 @@ func TestQMPStartStopLoop(t *testing.T) {
|
|||||||
<-disconnectedCh
|
<-disconnectedCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks that a call to QMPStart with an invalid path exits gracefully.
|
||||||
|
//
|
||||||
|
// We call QMPStart with an invalid path.
|
||||||
|
//
|
||||||
|
// An error should be returned and the disconnected channel should be closed.
|
||||||
|
func TestQMPStartBadPath(t *testing.T) {
|
||||||
|
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||||
|
disconnectedCh := make(chan struct{})
|
||||||
|
q, _, err := QMPStart(context.Background(), "", cfg, disconnectedCh)
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error")
|
||||||
|
q.Shutdown()
|
||||||
|
}
|
||||||
|
<-disconnectedCh
|
||||||
|
}
|
||||||
|
|
||||||
// Checks that the qmp_capabilities command is correctly sent.
|
// Checks that the qmp_capabilities command is correctly sent.
|
||||||
//
|
//
|
||||||
// We start a QMPLoop, send the qmp_capabilities command and stop the
|
// We start a QMPLoop, send the qmp_capabilities command and stop the
|
||||||
@ -274,6 +290,28 @@ func TestQMPCapabilities(t *testing.T) {
|
|||||||
<-disconnectedCh
|
<-disconnectedCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Checks that an error returned by a QMP command is correctly handled.
|
||||||
|
//
|
||||||
|
// We start a QMPLoop, send the qmp_capabilities command and stop the
|
||||||
|
// loop.
|
||||||
|
//
|
||||||
|
// The qmp_capabilities command fails and yet we should exit gracefully.
|
||||||
|
func TestQMPBadCapabilities(t *testing.T) {
|
||||||
|
connectedCh := make(chan *QMPVersion)
|
||||||
|
disconnectedCh := make(chan struct{})
|
||||||
|
buf := newQMPTestCommandBuffer(t)
|
||||||
|
buf.AddCommand("qmp_capabilities", nil, "error", nil)
|
||||||
|
cfg := QMPConfig{Logger: qmpTestLogger{}}
|
||||||
|
q := startQMPLoop(buf, cfg, connectedCh, disconnectedCh)
|
||||||
|
checkVersion(t, connectedCh)
|
||||||
|
err := q.ExecuteQMPCapabilities(context.Background())
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("Expected error")
|
||||||
|
}
|
||||||
|
q.Shutdown()
|
||||||
|
<-disconnectedCh
|
||||||
|
}
|
||||||
|
|
||||||
// Checks that the stop command is correctly sent.
|
// Checks that the stop command is correctly sent.
|
||||||
//
|
//
|
||||||
// We start a QMPLoop, send the stop command and stop the
|
// We start a QMPLoop, send the stop command and stop the
|
||||||
|
Loading…
Reference in New Issue
Block a user