moby/layer/layer_unix_test.go
Sebastiaan van Stijn 8a2e1245d4
runconfig, oci, image, layer, distribution: fix empty-lines (revive)
runconfig/config_test.go:23:46: empty-lines: extra empty line at the start of a block (revive)
    runconfig/config_test.go:75:55: empty-lines: extra empty line at the start of a block (revive)

    oci/devices_linux.go:57:34: empty-lines: extra empty line at the start of a block (revive)
    oci/devices_linux.go:60:69: empty-lines: extra empty line at the start of a block (revive)

    image/fs_test.go:53:38: empty-lines: extra empty line at the end of a block (revive)
    image/tarexport/save.go:88:29: empty-lines: extra empty line at the end of a block (revive)

    layer/layer_unix_test.go:21:34: empty-lines: extra empty line at the end of a block (revive)

    distribution/xfer/download.go:302:9: empty-lines: extra empty line at the end of a block (revive)
    distribution/manifest_test.go:154:99: empty-lines: extra empty line at the end of a block (revive)
    distribution/manifest_test.go:329:52: empty-lines: extra empty line at the end of a block (revive)
    distribution/manifest_test.go:354:59: empty-lines: extra empty line at the end of a block (revive)

    registry/config_test.go:323:42: empty-lines: extra empty line at the end of a block (revive)
    registry/config_test.go:350:33: empty-lines: extra empty line at the end of a block (revive)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-28 01:58:52 +02:00

66 lines
1.6 KiB
Go

//go:build !windows
// +build !windows
package layer // import "github.com/docker/docker/layer"
import (
"testing"
)
func graphDiffSize(ls Store, l Layer) (int64, error) {
cl := getCachedLayer(l)
var parent string
if cl.parent != nil {
parent = cl.parent.cacheID
}
return ls.(*layerStore).driver.DiffSize(cl.cacheID, parent)
}
// Unix as Windows graph driver does not support Changes which is indirectly
// invoked by calling DiffSize on the driver
func TestLayerSize(t *testing.T) {
ls, _, cleanup := newTestStore(t)
defer cleanup()
content1 := []byte("Base contents")
content2 := []byte("Added contents")
layer1, err := createLayer(ls, "", initWithFiles(newTestFile("file1", content1, 0644)))
if err != nil {
t.Fatal(err)
}
layer2, err := createLayer(ls, layer1.ChainID(), initWithFiles(newTestFile("file2", content2, 0644)))
if err != nil {
t.Fatal(err)
}
layer1DiffSize, err := graphDiffSize(ls, layer1)
if err != nil {
t.Fatal(err)
}
if int(layer1DiffSize) != len(content1) {
t.Fatalf("Unexpected diff size %d, expected %d", layer1DiffSize, len(content1))
}
layer1Size := layer1.Size()
if expected := len(content1); int(layer1Size) != expected {
t.Fatalf("Unexpected size %d, expected %d", layer1Size, expected)
}
layer2DiffSize, err := graphDiffSize(ls, layer2)
if err != nil {
t.Fatal(err)
}
if int(layer2DiffSize) != len(content2) {
t.Fatalf("Unexpected diff size %d, expected %d", layer2DiffSize, len(content2))
}
layer2Size := layer2.Size()
if expected := len(content1) + len(content2); int(layer2Size) != expected {
t.Fatalf("Unexpected size %d, expected %d", layer2Size, expected)
}
}