Skip to content

Commit

Permalink
Windows CI UnitTest TestLayerSize-->Unix
Browse files Browse the repository at this point in the history
Signed-off-by: John Howard <jhoward@microsoft.com>
  • Loading branch information
John Howard committed Feb 10, 2016
1 parent 2658341 commit 298d280
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 63 deletions.
63 changes: 0 additions & 63 deletions layer/layer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,66 +702,3 @@ func TestRegisterExistingLayer(t *testing.T) {

assertReferences(t, layer2a, layer2b)
}

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)
}

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, err := layer1.Size()
if err != nil {
t.Fatal(err)
}

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, err := layer2.Size()
if err != nil {
t.Fatal(err)
}

if expected := len(content1) + len(content2); int(layer2Size) != expected {
t.Fatalf("Unexpected size %d, expected %d", layer2Size, expected)
}
}
71 changes: 71 additions & 0 deletions layer/layer_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// +build !windows

package 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, err := layer1.Size()
if err != nil {
t.Fatal(err)
}

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, err := layer2.Size()
if err != nil {
t.Fatal(err)
}

if expected := len(content1) + len(content2); int(layer2Size) != expected {
t.Fatalf("Unexpected size %d, expected %d", layer2Size, expected)
}

}

0 comments on commit 298d280

Please sign in to comment.