500e77bad0
Layer store manages read-only and read-write layers on a union file system. Read only layers are always referenced by content addresses. Read-write layer identifiers are handled by the caller but upon registering its difference, the committed read-only layer will be referenced by content hash. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan) Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
46 lines
1 KiB
Go
46 lines
1 KiB
Go
package layer
|
|
|
|
import (
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/docker/distribution/digest"
|
|
)
|
|
|
|
func TestEmptyLayer(t *testing.T) {
|
|
if EmptyLayer.ChainID() != ChainID(DigestSHA256EmptyTar) {
|
|
t.Fatal("wrong ID for empty layer")
|
|
}
|
|
|
|
if EmptyLayer.DiffID() != DigestSHA256EmptyTar {
|
|
t.Fatal("wrong DiffID for empty layer")
|
|
}
|
|
|
|
if EmptyLayer.Parent() != nil {
|
|
t.Fatal("expected no parent for empty layer")
|
|
}
|
|
|
|
if size, err := EmptyLayer.Size(); err != nil || size != 0 {
|
|
t.Fatal("expected zero size for empty layer")
|
|
}
|
|
|
|
if diffSize, err := EmptyLayer.DiffSize(); err != nil || diffSize != 0 {
|
|
t.Fatal("expected zero diffsize for empty layer")
|
|
}
|
|
|
|
tarStream, err := EmptyLayer.TarStream()
|
|
if err != nil {
|
|
t.Fatalf("error streaming tar for empty layer: %v", err)
|
|
}
|
|
|
|
digester := digest.Canonical.New()
|
|
_, err = io.Copy(digester.Hash(), tarStream)
|
|
|
|
if err != nil {
|
|
t.Fatalf("error hashing empty tar layer: %v", err)
|
|
}
|
|
|
|
if digester.Digest() != digest.Digest(DigestSHA256EmptyTar) {
|
|
t.Fatal("empty layer tar stream hashes to wrong value")
|
|
}
|
|
}
|