Fix integration tests with a check for nil

Add a unit test to validate behavior
This commit is contained in:
Brendan Burns 2014-07-09 22:31:17 -07:00
parent 7b11cbd622
commit d5b7c4eb6d
2 changed files with 32 additions and 1 deletions

View File

@ -91,7 +91,11 @@ func (storage *PodRegistryStorage) fillPodInfo(pod *api.Pod) {
pod.CurrentState.Info = info
netContainerInfo, ok := info["net"]
if ok {
pod.CurrentState.PodIP = netContainerInfo.NetworkSettings.IPAddress
if netContainerInfo.NetworkSettings != nil {
pod.CurrentState.PodIP = netContainerInfo.NetworkSettings.IPAddress
} else {
glog.Warningf("No network settings: %#v", netContainerInfo)
}
} else {
glog.Warningf("Couldn't find network container in %v", info)
}

View File

@ -317,3 +317,30 @@ func TestFillPodInfo(t *testing.T) {
t.Errorf("Expected %s, saw %s", expectedIP, pod.CurrentState.PodIP)
}
}
func TestFillPodInfoNoData(t *testing.T) {
expectedIP := ""
fakeGetter := FakePodInfoGetter{
info: map[string]docker.Container{
"net": {
ID: "foobar",
Path: "bin/run.sh",
},
},
}
storage := PodRegistryStorage{
podCache: &fakeGetter,
}
pod := api.Pod{}
storage.fillPodInfo(&pod)
if !reflect.DeepEqual(fakeGetter.info, pod.CurrentState.Info) {
t.Errorf("Unexpected mis-match: %#v vs %#v", fakeGetter.info, pod.CurrentState.Info)
}
if pod.CurrentState.PodIP != expectedIP {
t.Errorf("Expected %s, saw %s", expectedIP, pod.CurrentState.PodIP)
}
}