github.com/reds/docker@v1.11.2-rc1/layer/layer_unix_test.go (about) 1 // +build !windows 2 3 package layer 4 5 import "testing" 6 7 func graphDiffSize(ls Store, l Layer) (int64, error) { 8 cl := getCachedLayer(l) 9 var parent string 10 if cl.parent != nil { 11 parent = cl.parent.cacheID 12 } 13 return ls.(*layerStore).driver.DiffSize(cl.cacheID, parent) 14 } 15 16 // Unix as Windows graph driver does not support Changes which is indirectly 17 // invoked by calling DiffSize on the driver 18 func TestLayerSize(t *testing.T) { 19 ls, _, cleanup := newTestStore(t) 20 defer cleanup() 21 22 content1 := []byte("Base contents") 23 content2 := []byte("Added contents") 24 25 layer1, err := createLayer(ls, "", initWithFiles(newTestFile("file1", content1, 0644))) 26 if err != nil { 27 t.Fatal(err) 28 } 29 30 layer2, err := createLayer(ls, layer1.ChainID(), initWithFiles(newTestFile("file2", content2, 0644))) 31 if err != nil { 32 t.Fatal(err) 33 } 34 35 layer1DiffSize, err := graphDiffSize(ls, layer1) 36 if err != nil { 37 t.Fatal(err) 38 } 39 40 if int(layer1DiffSize) != len(content1) { 41 t.Fatalf("Unexpected diff size %d, expected %d", layer1DiffSize, len(content1)) 42 } 43 44 layer1Size, err := layer1.Size() 45 if err != nil { 46 t.Fatal(err) 47 } 48 49 if expected := len(content1); int(layer1Size) != expected { 50 t.Fatalf("Unexpected size %d, expected %d", layer1Size, expected) 51 } 52 53 layer2DiffSize, err := graphDiffSize(ls, layer2) 54 if err != nil { 55 t.Fatal(err) 56 } 57 58 if int(layer2DiffSize) != len(content2) { 59 t.Fatalf("Unexpected diff size %d, expected %d", layer2DiffSize, len(content2)) 60 } 61 62 layer2Size, err := layer2.Size() 63 if err != nil { 64 t.Fatal(err) 65 } 66 67 if expected := len(content1) + len(content2); int(layer2Size) != expected { 68 t.Fatalf("Unexpected size %d, expected %d", layer2Size, expected) 69 } 70 71 }