github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/layer/empty_test.go (about)

     1  package layer // import "github.com/demonoid81/moby/layer"
     2  
     3  import (
     4  	"io"
     5  	"testing"
     6  
     7  	digest "github.com/opencontainers/go-digest"
     8  )
     9  
    10  func TestEmptyLayer(t *testing.T) {
    11  	if EmptyLayer.ChainID() != ChainID(DigestSHA256EmptyTar) {
    12  		t.Fatal("wrong ChainID for empty layer")
    13  	}
    14  
    15  	if EmptyLayer.DiffID() != DigestSHA256EmptyTar {
    16  		t.Fatal("wrong DiffID for empty layer")
    17  	}
    18  
    19  	if EmptyLayer.Parent() != nil {
    20  		t.Fatal("expected no parent for empty layer")
    21  	}
    22  
    23  	if size, err := EmptyLayer.Size(); err != nil || size != 0 {
    24  		t.Fatal("expected zero size for empty layer")
    25  	}
    26  
    27  	if diffSize, err := EmptyLayer.DiffSize(); err != nil || diffSize != 0 {
    28  		t.Fatal("expected zero diffsize for empty layer")
    29  	}
    30  
    31  	meta, err := EmptyLayer.Metadata()
    32  
    33  	if len(meta) != 0 || err != nil {
    34  		t.Fatal("expected zero length metadata for empty layer")
    35  	}
    36  
    37  	tarStream, err := EmptyLayer.TarStream()
    38  	if err != nil {
    39  		t.Fatalf("error streaming tar for empty layer: %v", err)
    40  	}
    41  
    42  	digester := digest.Canonical.Digester()
    43  	_, err = io.Copy(digester.Hash(), tarStream)
    44  
    45  	if err != nil {
    46  		t.Fatalf("error hashing empty tar layer: %v", err)
    47  	}
    48  
    49  	if digester.Digest() != digest.Digest(DigestSHA256EmptyTar) {
    50  		t.Fatal("empty layer tar stream hashes to wrong value")
    51  	}
    52  }