Browse code

integcli: fix map randomization failures

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)

unclejack authored on 2014/07/09 05:27:58
Showing 2 changed files
... ...
@@ -2,7 +2,6 @@ package main
2 2
 
3 3
 import (
4 4
 	"fmt"
5
-
6 5
 	"os"
7 6
 	"os/exec"
8 7
 	"path/filepath"
... ...
@@ -592,8 +591,12 @@ func TestBuildRm(t *testing.T) {
592 592
 }
593 593
 
594 594
 func TestBuildWithVolumes(t *testing.T) {
595
-	name := "testbuildvolumes"
596
-	expected := "map[/test1:map[] /test2:map[]]"
595
+	var (
596
+		result   map[string]map[string]struct{}
597
+		name     = "testbuildvolumes"
598
+		emptyMap = make(map[string]struct{})
599
+		expected = map[string]map[string]struct{}{"/test1": emptyMap, "/test2": emptyMap}
600
+	)
597 601
 	defer deleteImages(name)
598 602
 	_, err := buildImage(name,
599 603
 		`FROM scratch
... ...
@@ -603,13 +606,22 @@ func TestBuildWithVolumes(t *testing.T) {
603 603
 	if err != nil {
604 604
 		t.Fatal(err)
605 605
 	}
606
-	res, err := inspectField(name, "Config.Volumes")
606
+	res, err := inspectFieldJSON(name, "Config.Volumes")
607 607
 	if err != nil {
608 608
 		t.Fatal(err)
609 609
 	}
610
-	if res != expected {
611
-		t.Fatalf("Volumes %s, expected %s", res, expected)
610
+
611
+	err = unmarshalJSON([]byte(res), &result)
612
+	if err != nil {
613
+		t.Fatal(err)
612 614
 	}
615
+
616
+	equal := deepEqual(&expected, &result)
617
+
618
+	if !equal {
619
+		t.Fatalf("Volumes %s, expected %s", result, expected)
620
+	}
621
+
613 622
 	logDone("build - with volumes")
614 623
 }
615 624
 
... ...
@@ -93,16 +93,30 @@ func TestIpTablesRulesWhenLinkAndUnlink(t *testing.T) {
93 93
 }
94 94
 
95 95
 func TestInspectLinksStarted(t *testing.T) {
96
+	var (
97
+		expected = map[string]struct{}{"/container1:/testinspectlink/alias1": {}, "/container2:/testinspectlink/alias2": {}}
98
+		result   []string
99
+	)
96 100
 	defer deleteAllContainers()
97 101
 	cmd(t, "run", "-d", "--name", "container1", "busybox", "sleep", "10")
98 102
 	cmd(t, "run", "-d", "--name", "container2", "busybox", "sleep", "10")
99 103
 	cmd(t, "run", "-d", "--name", "testinspectlink", "--link", "container1:alias1", "--link", "container2:alias2", "busybox", "sleep", "10")
100
-	links, err := inspectField("testinspectlink", "HostConfig.Links")
104
+	links, err := inspectFieldJSON("testinspectlink", "HostConfig.Links")
101 105
 	if err != nil {
102 106
 		t.Fatal(err)
103 107
 	}
104
-	if expected := "[/container1:/testinspectlink/alias1 /container2:/testinspectlink/alias2]"; links != expected {
105
-		t.Fatalf("Links %s, but expected %s", links, expected)
108
+
109
+	err = unmarshalJSON([]byte(links), &result)
110
+	if err != nil {
111
+		t.Fatal(err)
112
+	}
113
+
114
+	output := convertSliceOfStringsToMap(result)
115
+
116
+	equal := deepEqual(expected, output)
117
+
118
+	if !equal {
119
+		t.Fatalf("Links %s, expected %s", result, expected)
106 120
 	}
107 121
 	logDone("link - links in started container inspect")
108 122
 }