From 137af244ee561bd350797c8ce6e159fbd46b6a02 Mon Sep 17 00:00:00 2001 From: creack Date: Fri, 15 Mar 2013 02:33:37 -0700 Subject: [PATCH] Add the health check to mount_test --- mount_test.go | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/mount_test.go b/mount_test.go index c3c9c53930..98354875ee 100644 --- a/mount_test.go +++ b/mount_test.go @@ -8,6 +8,41 @@ import ( "testing" ) +// Look for inconsistencies in a store. +func healthCheck(store *Store) error { + parents := make(map[string]bool) + paths, err := store.Paths() + if err != nil { + return err + } + for _, path := range paths { + images, err := store.List(path) + if err != nil { + return err + } + IDs := make(map[string]bool) // All IDs for this path + for _, img := range images { + // Check for duplicate IDs per path + if _, exists := IDs[img.Id]; exists { + return errors.New(fmt.Sprintf("Duplicate ID: %s", img.Id)) + } else { + IDs[img.Id] = true + } + // Store parent for 2nd pass + if parent := img.Parent; parent != "" { + parents[parent] = true + } + } + } + // Check non-existing parents + for parent := range parents { + if _, exists := parents[parent]; !exists { + return errors.New("Reference to non-registered parent: " + parent) + } + } + return nil +} + // Note: This test is in the docker package because he needs to be run as root func TestMount(t *testing.T) { dir, err := ioutil.TempDir("", "docker-fs-test-mount") @@ -73,7 +108,7 @@ func TestMount(t *testing.T) { t.Fatal("Wrong number of mountpoints registered (should be %d, not %d)", 0, len(mps)) } // General health check - // if err := healthCheck(store); err != nil { - // t.Fatal(err) - // } + if err := healthCheck(store); err != nil { + t.Fatal(err) + } }