2021-08-23 13:14:53 +00:00
|
|
|
//go:build !windows
|
2016-02-10 21:57:26 +00:00
|
|
|
|
2018-02-05 21:05:59 +00:00
|
|
|
package layer // import "github.com/docker/docker/layer"
|
2016-02-10 21:57:26 +00:00
|
|
|
|
2017-08-24 18:48:16 +00:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
2016-02-10 21:57:26 +00:00
|
|
|
|
|
|
|
func graphDiffSize(ls Store, l Layer) (int64, error) {
|
|
|
|
cl := getCachedLayer(l)
|
|
|
|
var parent string
|
|
|
|
if cl.parent != nil {
|
|
|
|
parent = cl.parent.cacheID
|
|
|
|
}
|
2017-09-19 19:14:46 +00:00
|
|
|
return ls.(*layerStore).driver.DiffSize(cl.cacheID, parent)
|
2016-02-10 21:57:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Unix as Windows graph driver does not support Changes which is indirectly
|
|
|
|
// invoked by calling DiffSize on the driver
|
|
|
|
func TestLayerSize(t *testing.T) {
|
2016-02-09 19:38:37 +00:00
|
|
|
ls, _, cleanup := newTestStore(t)
|
2016-02-10 21:57:26 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
content1 := []byte("Base contents")
|
|
|
|
content2 := []byte("Added contents")
|
|
|
|
|
2022-10-05 14:39:56 +00:00
|
|
|
layer1, err := createLayer(ls, "", initWithFiles(newTestFile("file1", content1, 0o644)))
|
2016-02-10 21:57:26 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2022-10-05 14:39:56 +00:00
|
|
|
layer2, err := createLayer(ls, layer1.ChainID(), initWithFiles(newTestFile("file2", content2, 0o644)))
|
2016-02-10 21:57:26 +00:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2022-01-21 18:01:34 +00:00
|
|
|
layer1Size := layer1.Size()
|
2016-02-10 21:57:26 +00:00
|
|
|
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))
|
|
|
|
}
|
|
|
|
|
2022-01-21 18:01:34 +00:00
|
|
|
layer2Size := layer2.Size()
|
2016-02-10 21:57:26 +00:00
|
|
|
|
|
|
|
if expected := len(content1) + len(content2); int(layer2Size) != expected {
|
|
|
|
t.Fatalf("Unexpected size %d, expected %d", layer2Size, expected)
|
|
|
|
}
|
|
|
|
}
|