github.com/reds/docker@v1.11.2-rc1/layer/empty_test.go (about)

     1  package layer
     2  
     3  import (
     4  	"io"
     5  	"testing"
     6  
     7  	"github.com/docker/distribution/digest"
     8  )
     9  
    10  func TestEmptyLayer(t *testing.T) {
    11  	if EmptyLayer.ChainID() != ChainID(DigestSHA256EmptyTar) {
    12  		t.Fatal("wrong ID 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  	tarStream, err := EmptyLayer.TarStream()
    32  	if err != nil {
    33  		t.Fatalf("error streaming tar for empty layer: %v", err)
    34  	}
    35  
    36  	digester := digest.Canonical.New()
    37  	_, err = io.Copy(digester.Hash(), tarStream)
    38  
    39  	if err != nil {
    40  		t.Fatalf("error hashing empty tar layer: %v", err)
    41  	}
    42  
    43  	if digester.Digest() != digest.Digest(DigestSHA256EmptyTar) {
    44  		t.Fatal("empty layer tar stream hashes to wrong value")
    45  	}
    46  }