FIX nil pointer dereference in machine ls

Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
David Gageot 2015-11-24 17:57:42 +01:00
parent 6a1993664d
commit 00f62150b4
2 changed files with 27 additions and 1 deletions

View File

@ -244,13 +244,18 @@ func attemptGetHostState(h *host.Host, stateQueryChan chan<- HostListItem) {
hostError = ""
}
var swarmOptions *swarm.Options
if h.HostOptions != nil {
swarmOptions = h.HostOptions.SwarmOptions
}
stateQueryChan <- HostListItem{
Name: h.Name,
Active: isActive(currentState, url),
DriverName: h.Driver.DriverName(),
State: currentState,
URL: url,
SwarmOptions: h.HostOptions.SwarmOptions,
SwarmOptions: swarmOptions,
Error: hostError,
}
}

View File

@ -455,3 +455,24 @@ func TestGetHostStateTimeout(t *testing.T) {
stateTimeoutDuration = originalTimeout
}
func TestGetHostStateError(t *testing.T) {
hosts := []*host.Host{
{
Name: "foo",
Driver: &fakedriver.Driver{
MockState: state.Error,
},
},
}
hostItems := getHostListItems(hosts)
hostItem := hostItems[0]
assert.Equal(t, "foo", hostItem.Name)
assert.Equal(t, state.Error, hostItem.State)
assert.Equal(t, "Driver", hostItem.DriverName)
assert.Empty(t, hostItem.URL)
assert.Equal(t, "Unable to get ip", hostItem.Error)
assert.Nil(t, hostItem.SwarmOptions)
}