Browse code

Ported test for image deletion

Solomon Hykes authored on 2013/03/19 09:57:18
Showing 1 changed files
... ...
@@ -118,6 +118,54 @@ func TestMount(t *testing.T) {
118 118
 	}()
119 119
 }
120 120
 
121
+func TestDelete(t *testing.T) {
122
+	graph := tempGraph(t)
123
+	defer os.RemoveAll(graph.Root)
124
+	archive, err := fake.FakeTar()
125
+	if err != nil {
126
+		t.Fatal(err)
127
+	}
128
+	assertNImages(graph, t, 0)
129
+	img, err := graph.Create(archive, "", "Bla bla")
130
+	if err != nil {
131
+		t.Fatal(err)
132
+	}
133
+	assertNImages(graph, t, 1)
134
+	if err := graph.Delete(img.Id); err != nil {
135
+		t.Fatal(err)
136
+	}
137
+	assertNImages(graph, t, 0)
138
+
139
+	// Test 2 create (same name) / 1 delete
140
+	img1, err := graph.Create(archive, "foo", "Testing")
141
+	if err != nil {
142
+		t.Fatal(err)
143
+	}
144
+	if _, err = graph.Create(archive, "foo", "Testing"); err != nil {
145
+		t.Fatal(err)
146
+	}
147
+	assertNImages(graph, t, 2)
148
+	if err := graph.Delete(img1.Id); err != nil {
149
+		t.Fatal(err)
150
+	}
151
+	assertNImages(graph, t, 1)
152
+
153
+	// Test delete wrong name
154
+	if err := graph.Delete("Not_foo"); err == nil {
155
+		t.Fatalf("Deleting wrong ID should return an error")
156
+	}
157
+	assertNImages(graph, t, 1)
158
+
159
+}
160
+
161
+func assertNImages(graph *Graph, t *testing.T, n int) {
162
+	if images, err := graph.All(); err != nil {
163
+		t.Fatal(err)
164
+	} else if actualN := len(images); actualN != n {
165
+		t.Fatalf("Expected %d images, found %d", n, actualN)
166
+	}
167
+}
168
+
121 169
 /*
122 170
  * HELPER FUNCTIONS
123 171
  */