github.com/moby/docker@v26.1.3+incompatible/layer/empty_test.go (about) 1 package layer // import "github.com/docker/docker/layer" 2 3 import ( 4 "io" 5 "testing" 6 7 "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 := EmptyLayer.Size(); size != 0 { 24 t.Fatal("expected zero size for empty layer") 25 } 26 27 if diffSize := EmptyLayer.DiffSize(); 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 }