Add a new e2e test; fix some bugs/usability problems

This commit is contained in:
Daniel Smith
2014-06-13 16:26:38 -07:00
parent a40529b379
commit 5626703634
5 changed files with 103 additions and 27 deletions

View File

@@ -90,14 +90,14 @@ func (client Client) rawRequest(method, path string, requestBody io.Reader, targ
if err != nil {
return nil, err
}
if response.StatusCode != 200 {
return nil, fmt.Errorf("request [%s %s] failed (%d) %s", method, client.makeURL(path), response.StatusCode, response.Status)
}
defer response.Body.Close()
body, err := ioutil.ReadAll(response.Body)
if err != nil {
return body, err
}
if response.StatusCode != 200 {
return nil, fmt.Errorf("request [%s %s] failed (%d) %s: %s", method, client.makeURL(path), response.StatusCode, response.Status, string(body))
}
if target != nil {
err = json.Unmarshal(body, target)
}

View File

@@ -190,15 +190,22 @@ func (h *HumanReadablePrinter) extractObject(data, kind string) (interface{}, er
func (h *HumanReadablePrinter) Print(data string, output io.Writer) error {
w := tabwriter.NewWriter(output, 20, 5, 3, ' ', 0)
defer w.Flush()
var obj interface{}
if err := json.Unmarshal([]byte(data), &obj); err != nil {
var mapObj map[string]interface{}
if err := json.Unmarshal([]byte(data), &mapObj); err != nil {
return err
}
if _, contains := obj.(map[string]interface{})["kind"]; !contains {
// Don't complain about empty objects returned by DELETE commands.
if len(mapObj) == 0 {
fmt.Fprint(w, "<empty>")
return nil
}
if _, contains := mapObj["kind"]; !contains {
return fmt.Errorf("unexpected object with no 'kind' field: %s", data)
}
kind := (obj.(map[string]interface{})["kind"]).(string)
kind := (mapObj["kind"]).(string)
obj, err := h.extractObject(data, kind)
if err != nil {
return err