integcli: add JSON utils for testing

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
unclejack 2014-07-08 23:25:22 +03:00
parent dca52c47a4
commit e5e8669c72
2 changed files with 33 additions and 0 deletions

View File

@ -211,6 +211,16 @@ func inspectField(name, field string) (string, error) {
return strings.TrimSpace(out), nil
}
func inspectFieldJSON(name, field string) (string, error) {
format := fmt.Sprintf("{{json .%s}}", field)
inspectCmd := exec.Command(dockerBinary, "inspect", "-f", format, name)
out, exitCode, err := runCommandWithOutput(inspectCmd)
if err != nil || exitCode != 0 {
return "", fmt.Errorf("failed to inspect %s: %s", name, out)
}
return strings.TrimSpace(out), nil
}
func getIDByName(name string) (string, error) {
return inspectField(name, "Id")
}

View File

@ -2,9 +2,11 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"os/exec"
"reflect"
"strings"
"syscall"
"testing"
@ -111,3 +113,24 @@ func errorOutOnNonNilError(err error, t *testing.T, message string) {
func nLines(s string) int {
return strings.Count(s, "\n")
}
func unmarshalJSON(data []byte, result interface{}) error {
err := json.Unmarshal(data, result)
if err != nil {
return err
}
return nil
}
func deepEqual(expected interface{}, result interface{}) bool {
return reflect.DeepEqual(result, expected)
}
func convertSliceOfStringsToMap(input []string) map[string]struct{} {
output := make(map[string]struct{})
for _, v := range input {
output[v] = struct{}{}
}
return output
}