diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 74576ba489..e3e5b36d93 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -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") } diff --git a/integration-cli/utils.go b/integration-cli/utils.go index ae7af52687..c414c9a2d9 100644 --- a/integration-cli/utils.go +++ b/integration-cli/utils.go @@ -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 +}