2015-11-18 17:15:00 -05:00
|
|
|
package layer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
|
2017-01-06 20:23:18 -05:00
|
|
|
"github.com/opencontainers/go-digest"
|
2015-11-18 17:15:00 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestEmptyLayer(t *testing.T) {
|
|
|
|
if EmptyLayer.ChainID() != ChainID(DigestSHA256EmptyTar) {
|
2017-03-09 03:59:04 -05:00
|
|
|
t.Fatal("wrong ChainID for empty layer")
|
2015-11-18 17:15:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2017-09-14 02:15:23 -04:00
|
|
|
meta, err := EmptyLayer.Metadata()
|
|
|
|
|
|
|
|
if len(meta) != 0 || err != nil {
|
|
|
|
t.Fatal("expected zero length metadata for empty layer")
|
|
|
|
}
|
|
|
|
|
2015-11-18 17:15:00 -05:00
|
|
|
tarStream, err := EmptyLayer.TarStream()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("error streaming tar for empty layer: %v", err)
|
|
|
|
}
|
|
|
|
|
2017-01-06 20:23:18 -05:00
|
|
|
digester := digest.Canonical.Digester()
|
2015-11-18 17:15:00 -05: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")
|
|
|
|
}
|
|
|
|
}
|