mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Added tests for checksum computation in layer store
This commit is contained in:
parent
edf2e20e28
commit
6d1054619d
1 changed files with 48 additions and 0 deletions
48
image/layers_test.go
Normal file
48
image/layers_test.go
Normal file
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue