2018-02-05 21:05:59 +00:00
|
|
|
package layer // import "github.com/docker/docker/layer"
|
2015-11-18 22:15:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
|
2022-03-04 13:49:42 +00:00
|
|
|
"github.com/opencontainers/go-digest"
|
2015-11-18 22:15:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEmptyLayer(t *testing.T) {
|
|
|
|
if EmptyLayer.ChainID() != ChainID(DigestSHA256EmptyTar) {
|
2017-03-09 08:59:04 +00:00
|
|
|
t.Fatal("wrong ChainID for empty layer")
|
2015-11-18 22:15:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if EmptyLayer.DiffID() != DigestSHA256EmptyTar {
|
|
|
|
t.Fatal("wrong DiffID for empty layer")
|
|
|
|
}
|
|
|
|
|
|
|
|
if EmptyLayer.Parent() != nil {
|
|
|
|
t.Fatal("expected no parent for empty layer")
|
|
|
|
}
|
|
|
|
|
2022-01-21 18:01:34 +00:00
|
|
|
if size := EmptyLayer.Size(); size != 0 {
|
2015-11-18 22:15:00 +00:00
|
|
|
t.Fatal("expected zero size for empty layer")
|
|
|
|
}
|
|
|
|
|
2022-01-21 18:01:34 +00:00
|
|
|
if diffSize := EmptyLayer.DiffSize(); diffSize != 0 {
|
2015-11-18 22:15:00 +00:00
|
|
|
t.Fatal("expected zero diffsize for empty layer")
|
|
|
|
}
|
|
|
|
|
2017-09-14 06:15:23 +00:00
|
|
|
meta, err := EmptyLayer.Metadata()
|
|
|
|
|
|
|
|
if len(meta) != 0 || err != nil {
|
|
|
|
t.Fatal("expected zero length metadata for empty layer")
|
|
|
|
}
|
|
|
|
|
2015-11-18 22:15:00 +00:00
|
|
|
tarStream, err := EmptyLayer.TarStream()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error streaming tar for empty layer: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-01-07 01:23:18 +00:00
|
|
|
digester := digest.Canonical.Digester()
|
2015-11-18 22:15:00 +00:00
|
|
|
_, 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")
|
|
|
|
}
|
|
|
|
}
|