mirror of https://github.com/docker/docs.git
FIX nil pointer dereference in machine ls
Signed-off-by: David Gageot <david@gageot.net>
This commit is contained in:
parent
6a1993664d
commit
00f62150b4
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue