Merge pull request #92 from brendandburns/container_info

Add status message population.
pull/6/head
Daniel Smith 2014-06-13 10:49:32 -07:00
commit 9cd9754693
2 changed files with 41 additions and 1 deletions

View File

@ -80,6 +80,19 @@ func (storage *PodRegistryStorage) List(url *url.URL) (interface{}, error) {
return result, err
}
func makePodStatus(info interface{}) string {
if state, ok := info.(map[string]interface{})["State"]; ok {
if running, ok := state.(map[string]interface{})["Running"]; ok {
if running.(bool) {
return "Running"
} else {
return "Stopped"
}
}
}
return "Pending"
}
func (storage *PodRegistryStorage) Get(id string) (interface{}, error) {
pod, err := storage.registry.GetPod(id)
if err != nil {
@ -90,6 +103,7 @@ func (storage *PodRegistryStorage) Get(id string) (interface{}, error) {
return pod, err
}
pod.CurrentState.Info = info
pod.CurrentState.Status = makePodStatus(info)
pod.Kind = "cluster#pod"
return pod, err
}

View File

@ -201,5 +201,31 @@ func TestLabelsMatch(t *testing.T) {
"foobar": "bar",
"baz": "blah",
})
}
func TestMakePodStatus(t *testing.T) {
status := makePodStatus(map[string]interface{}{})
if status != "Pending" {
t.Errorf("Expected 'Pending', got '%s'", status)
}
status = makePodStatus(map[string]interface{}{
"State": map[string]interface{}{
"Running": false,
},
})
if status != "Stopped" {
t.Errorf("Expected 'Stopped', got '%s'", status)
}
status = makePodStatus(map[string]interface{}{
"State": map[string]interface{}{
"Running": true,
},
})
if status != "Running" {
t.Errorf("Expected 'Running', got '%s'", status)
}
}