Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
| ... | ... |
@@ -211,6 +211,16 @@ func inspectField(name, field string) (string, error) {
|
| 211 | 211 |
return strings.TrimSpace(out), nil |
| 212 | 212 |
} |
| 213 | 213 |
|
| 214 |
+func inspectFieldJSON(name, field string) (string, error) {
|
|
| 215 |
+ format := fmt.Sprintf("{{json .%s}}", field)
|
|
| 216 |
+ inspectCmd := exec.Command(dockerBinary, "inspect", "-f", format, name) |
|
| 217 |
+ out, exitCode, err := runCommandWithOutput(inspectCmd) |
|
| 218 |
+ if err != nil || exitCode != 0 {
|
|
| 219 |
+ return "", fmt.Errorf("failed to inspect %s: %s", name, out)
|
|
| 220 |
+ } |
|
| 221 |
+ return strings.TrimSpace(out), nil |
|
| 222 |
+} |
|
| 223 |
+ |
|
| 214 | 224 |
func getIDByName(name string) (string, error) {
|
| 215 | 225 |
return inspectField(name, "Id") |
| 216 | 226 |
} |
| ... | ... |
@@ -2,9 +2,11 @@ package main |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 |
+ "encoding/json" |
|
| 5 | 6 |
"fmt" |
| 6 | 7 |
"io" |
| 7 | 8 |
"os/exec" |
| 9 |
+ "reflect" |
|
| 8 | 10 |
"strings" |
| 9 | 11 |
"syscall" |
| 10 | 12 |
"testing" |
| ... | ... |
@@ -111,3 +113,24 @@ func errorOutOnNonNilError(err error, t *testing.T, message string) {
|
| 111 | 111 |
func nLines(s string) int {
|
| 112 | 112 |
return strings.Count(s, "\n") |
| 113 | 113 |
} |
| 114 |
+ |
|
| 115 |
+func unmarshalJSON(data []byte, result interface{}) error {
|
|
| 116 |
+ err := json.Unmarshal(data, result) |
|
| 117 |
+ if err != nil {
|
|
| 118 |
+ return err |
|
| 119 |
+ } |
|
| 120 |
+ |
|
| 121 |
+ return nil |
|
| 122 |
+} |
|
| 123 |
+ |
|
| 124 |
+func deepEqual(expected interface{}, result interface{}) bool {
|
|
| 125 |
+ return reflect.DeepEqual(result, expected) |
|
| 126 |
+} |
|
| 127 |
+ |
|
| 128 |
+func convertSliceOfStringsToMap(input []string) map[string]struct{} {
|
|
| 129 |
+ output := make(map[string]struct{})
|
|
| 130 |
+ for _, v := range input {
|
|
| 131 |
+ output[v] = struct{}{}
|
|
| 132 |
+ } |
|
| 133 |
+ return output |
|
| 134 |
+} |