From 6d1054619d6d254ea3df0484cacb3c6778d58cd9 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Tue, 26 Feb 2013 09:46:29 -0800 Subject: [PATCH] Added tests for checksum computation in layer store --- image/layers_test.go | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 image/layers_test.go diff --git a/image/layers_test.go b/image/layers_test.go new file mode 100644 index 0000000000..a69edb1892 --- /dev/null +++ b/image/layers_test.go @@ -0,0 +1,48 @@ +package image + +import ( + "os" + "testing" + "io/ioutil" + "bytes" + "github.com/dotcloud/docker/future" + "github.com/dotcloud/docker/fake" +) + +func TestAddLayer(t *testing.T) { + tmp, err := ioutil.TempDir("", "docker-test-image") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmp) + store, err := NewLayerStore(tmp) + if err != nil { + t.Fatal(err) + } + archive, err := fake.FakeTar() + if err != nil { + t.Fatal(err) + } + layer, err := store.AddLayer(archive) + if err != nil { + t.Fatal(err) + } + if _, err := os.Stat(layer); err != nil { + t.Fatalf("Error testing for existence of layer: %s\n", err.Error()) + } +} + +func TestComputeId(t *testing.T) { + id1, err := future.ComputeId(bytes.NewBufferString("hello world\n")) + if err != nil { + t.Fatal(err) + } + id2, err := future.ComputeId(bytes.NewBufferString("foo bar\n")) + if err != nil { + t.Fatal(err) + } + if id1 == id2 { + t.Fatalf("Identical checksums for difference content (%s == %s)", id1, id2) + } +} +