From 820f97f5c8a4ac000b50debceeeb48fb92cae435 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Mon, 18 Mar 2013 17:57:18 -0700 Subject: [PATCH] Ported test for image deletion Upstream-commit: 3c1db4ca43ecd741c50e884c2ea3aac43e3191e1 Component: engine --- components/engine/graph/graph_test.go | 48 +++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/components/engine/graph/graph_test.go b/components/engine/graph/graph_test.go index 8487aaf1df..0fbebb8948 100644 --- a/components/engine/graph/graph_test.go +++ b/components/engine/graph/graph_test.go @@ -118,6 +118,54 @@ func TestMount(t *testing.T) { }() } +func TestDelete(t *testing.T) { + graph := tempGraph(t) + defer os.RemoveAll(graph.Root) + archive, err := fake.FakeTar() + if err != nil { + t.Fatal(err) + } + assertNImages(graph, t, 0) + img, err := graph.Create(archive, "", "Bla bla") + if err != nil { + t.Fatal(err) + } + assertNImages(graph, t, 1) + if err := graph.Delete(img.Id); err != nil { + t.Fatal(err) + } + assertNImages(graph, t, 0) + + // Test 2 create (same name) / 1 delete + img1, err := graph.Create(archive, "foo", "Testing") + if err != nil { + t.Fatal(err) + } + if _, err = graph.Create(archive, "foo", "Testing"); err != nil { + t.Fatal(err) + } + assertNImages(graph, t, 2) + if err := graph.Delete(img1.Id); err != nil { + t.Fatal(err) + } + assertNImages(graph, t, 1) + + // Test delete wrong name + if err := graph.Delete("Not_foo"); err == nil { + t.Fatalf("Deleting wrong ID should return an error") + } + assertNImages(graph, t, 1) + +} + +func assertNImages(graph *Graph, t *testing.T, n int) { + if images, err := graph.All(); err != nil { + t.Fatal(err) + } else if actualN := len(images); actualN != n { + t.Fatalf("Expected %d images, found %d", n, actualN) + } +} + /* * HELPER FUNCTIONS */