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:
parent
dca52c47a4
commit
e5e8669c72
|
@ -211,6 +211,16 @@ func inspectField(name, field string) (string, error) {
|
||||||
return strings.TrimSpace(out), nil
|
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) {
|
func getIDByName(name string) (string, error) {
|
||||||
return inspectField(name, "Id")
|
return inspectField(name, "Id")
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,9 +2,11 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -111,3 +113,24 @@ func errorOutOnNonNilError(err error, t *testing.T, message string) {
|
||||||
func nLines(s string) int {
|
func nLines(s string) int {
|
||||||
return strings.Count(s, "\n")
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue