mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 07:20:13 +00:00
Fix integration tests with a check for nil
Add a unit test to validate behavior
This commit is contained in:
parent
7b11cbd622
commit
d5b7c4eb6d
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user