зеркало из https://github.com/microsoft/docker.git
Added tests for checksum computation in layer store
This commit is contained in:
Родитель
edf2e20e28
Коммит
6d1054619d
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Загрузка…
Ссылка в новой задаче