Commit 23003500 authored by Daniel P. Berrange's avatar Daniel P. Berrange

Change GetState to return a pair of values, instead of array

Change GetState so it returns state and reason separately
instead of using an array, so state can be strongly typed.
Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
parent 6d2ff770
......@@ -1039,7 +1039,7 @@ func (d *Domain) GetName() (string, error) {
return C.GoString(name), nil
}
func (d *Domain) GetState() ([]int, error) {
func (d *Domain) GetState() (DomainState, int, error) {
var cState C.int
var cReason C.int
result := C.virDomainGetState(d.ptr,
......@@ -1047,9 +1047,9 @@ func (d *Domain) GetState() ([]int, error) {
(*C.int)(unsafe.Pointer(&cReason)),
0)
if int(result) == -1 {
return []int{}, GetLastError()
return 0, 0, GetLastError()
}
return []int{int(cState), int(cReason)}, nil
return DomainState(cState), int(cReason), nil
}
func (d *Domain) GetID() (uint, error) {
......
......@@ -98,17 +98,17 @@ func TestGetDomainState(t *testing.T) {
t.Errorf("CloseConnection() == %d, expected 0", res)
}
}()
state, err := dom.GetState()
state, reason, err := dom.GetState()
if err != nil {
t.Error(err)
return
}
if len(state) != 2 {
t.Error("Length of domain state should be 2")
if state != DOMAIN_SHUTOFF {
t.Error("Domain state in test transport should be shutoff")
return
}
if state[0] != 5 || state[1] != 0 {
t.Error("Domain state in test transport should be [5 0]")
if DomainShutoffReason(reason) != DOMAIN_SHUTOFF_UNKNOWN {
t.Error("Domain reason in test transport should be unknown")
return
}
}
......@@ -281,28 +281,36 @@ func TestCreateDestroyDomain(t *testing.T) {
t.Error(err)
return
}
state, err := dom.GetState()
state, reason, err := dom.GetState()
if err != nil {
t.Error(err)
return
}
if DomainState(state[0]) != DOMAIN_RUNNING {
if state != DOMAIN_RUNNING {
t.Fatal("Domain should be running")
return
}
if DomainRunningReason(reason) != DOMAIN_RUNNING_BOOTED {
t.Fatal("Domain reason should be booted")
return
}
if err = dom.Destroy(); err != nil {
t.Error(err)
return
}
state, err = dom.GetState()
state, reason, err = dom.GetState()
if err != nil {
t.Error(err)
return
}
if DomainState(state[0]) != DOMAIN_SHUTOFF {
if state != DOMAIN_SHUTOFF {
t.Fatal("Domain should be destroyed")
return
}
if DomainShutoffReason(reason) != DOMAIN_SHUTOFF_DESTROYED {
t.Fatal("Domain reason should be destroyed")
return
}
}
func TestShutdownDomain(t *testing.T) {
......@@ -321,13 +329,17 @@ func TestShutdownDomain(t *testing.T) {
t.Error(err)
return
}
state, err := dom.GetState()
state, reason, err := dom.GetState()
if err != nil {
t.Error(err)
return
}
if state[0] != 5 || state[1] != 1 {
t.Fatal("state should be [5 1]")
if state != DOMAIN_SHUTOFF {
t.Error("Domain state in test transport should be shutoff")
return
}
if DomainShutoffReason(reason) != DOMAIN_SHUTOFF_SHUTDOWN {
t.Error("Domain reason in test transport should be shutdown")
return
}
}
......@@ -554,13 +566,17 @@ func TesDomainShutdownFlags(t *testing.T) {
t.Error(err)
return
}
state, err := dom.GetState()
state, reason, err := dom.GetState()
if err != nil {
t.Error(err)
return
}
if state[0] != 5 || state[1] != 1 {
t.Fatal("state should be [5 1]")
if state != DOMAIN_SHUTOFF {
t.Error("Domain state in test transport should be shutoff")
return
}
if DomainShutoffReason(reason) != DOMAIN_SHUTOFF_SHUTDOWN {
t.Error("Domain reason in test transport should be shutdown")
return
}
}
......@@ -580,13 +596,17 @@ func TesDomainDestoryFlags(t *testing.T) {
t.Error(err)
return
}
state, err := dom.GetState()
state, reason, err := dom.GetState()
if err != nil {
t.Error(err)
return
}
if state[0] != 5 || state[1] != 1 {
t.Fatal("state should be [5 1]")
if state != DOMAIN_SHUTOFF {
t.Error("Domain state in test transport should be shutoff")
return
}
if DomainShutoffReason(reason) != DOMAIN_SHUTOFF_SHUTDOWN {
t.Error("Domain reason in test transport should be shutdown")
return
}
}
......
......@@ -200,14 +200,19 @@ func TestDomainCreateWithFlags(t *testing.T) {
}()
if err := dom.CreateWithFlags(DOMAIN_START_PAUSED); err != nil {
state, err := dom.GetState()
state, reason, err := dom.GetState()
if err != nil {
t.Error(err)
return
}
if DomainState(state[0]) != DOMAIN_PAUSED {
if state != DOMAIN_PAUSED {
t.Fatalf("Domain should be paused")
return
}
if DomainPausedReason(reason) != DOMAIN_PAUSED_STARTING_UP {
t.Fatal("Domain reason should be starting up")
return
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment