Merge pull request #55 from alexlarsson/dm-plugins-cleanup-graph-test

graph_test: Clean up drivers allocated in tempGraph()
This commit is contained in:
Guillaume J. Charmes 2013-11-20 10:41:18 -08:00
commit 6ebb236aa1
2 changed files with 13 additions and 7 deletions

View file

@ -16,7 +16,7 @@ import (
func TestInit(t *testing.T) {
graph := tempGraph(t)
defer os.RemoveAll(graph.Root)
defer nukeGraph(graph)
// Root should exist
if _, err := os.Stat(graph.Root); err != nil {
t.Fatal(err)
@ -32,7 +32,7 @@ func TestInit(t *testing.T) {
// Test that Register can be interrupted cleanly without side effects
func TestInterruptedRegister(t *testing.T) {
graph := tempGraph(t)
defer os.RemoveAll(graph.Root)
defer nukeGraph(graph)
badArchive, w := io.Pipe() // Use a pipe reader as a fake archive which never yields data
image := &Image{
ID: GenerateID(),
@ -59,7 +59,7 @@ func TestInterruptedRegister(t *testing.T) {
// create multiple, check the amount of images and paths, etc..)
func TestGraphCreate(t *testing.T) {
graph := tempGraph(t)
defer os.RemoveAll(graph.Root)
defer nukeGraph(graph)
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
@ -90,7 +90,7 @@ func TestGraphCreate(t *testing.T) {
func TestRegister(t *testing.T) {
graph := tempGraph(t)
defer os.RemoveAll(graph.Root)
defer nukeGraph(graph)
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
@ -124,7 +124,7 @@ func TestRegister(t *testing.T) {
// Test that an image can be deleted by its shorthand prefix
func TestDeletePrefix(t *testing.T) {
graph := tempGraph(t)
defer os.RemoveAll(graph.Root)
defer nukeGraph(graph)
img := createTestImage(graph, t)
if err := graph.Delete(utils.TruncateID(img.ID)); err != nil {
t.Fatal(err)
@ -146,7 +146,7 @@ func createTestImage(graph *Graph, t *testing.T) *Image {
func TestDelete(t *testing.T) {
graph := tempGraph(t)
defer os.RemoveAll(graph.Root)
defer nukeGraph(graph)
archive, err := fakeTar()
if err != nil {
t.Fatal(err)
@ -210,7 +210,7 @@ func TestByParent(t *testing.T) {
archive3, _ := fakeTar()
graph := tempGraph(t)
defer os.RemoveAll(graph.Root)
defer nukeGraph(graph)
parentImage := &Image{
ID: GenerateID(),
Comment: "parent",
@ -271,6 +271,11 @@ func tempGraph(t *testing.T) *Graph {
return graph
}
func nukeGraph(graph *Graph) {
graph.driver.Cleanup()
os.RemoveAll(graph.Root)
}
func testArchive(t *testing.T) archive.Archive {
archive, err := fakeTar()
if err != nil {

View file

@ -47,6 +47,7 @@ func TestLookupImage(t *testing.T) {
}
defer os.RemoveAll(tmp)
store := mkTestTagStore(tmp, t)
defer store.graph.driver.Cleanup()
if img, err := store.LookupImage(testImageName); err != nil {
t.Fatal(err)