mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
graphdriver/aufs: fix tmp cleanup in tests
Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
parent
db7fded17f
commit
4180579313
1 changed files with 19 additions and 15 deletions
|
@ -4,16 +4,18 @@ import (
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/docker/docker/daemon/graphdriver"
|
|
||||||
"github.com/docker/docker/pkg/archive"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/daemon/graphdriver"
|
||||||
|
"github.com/docker/docker/pkg/archive"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
tmp = path.Join(os.TempDir(), "aufs-tests", "aufs")
|
tmpOuter = path.Join(os.TempDir(), "aufs-tests")
|
||||||
|
tmp = path.Join(tmpOuter, "aufs")
|
||||||
)
|
)
|
||||||
|
|
||||||
func testInit(dir string, t *testing.T) graphdriver.Driver {
|
func testInit(dir string, t *testing.T) graphdriver.Driver {
|
||||||
|
@ -640,8 +642,8 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d := testInit(mountPath, t).(*Driver)
|
|
||||||
defer os.RemoveAll(mountPath)
|
defer os.RemoveAll(mountPath)
|
||||||
|
d := testInit(mountPath, t).(*Driver)
|
||||||
defer d.Cleanup()
|
defer d.Cleanup()
|
||||||
var last string
|
var last string
|
||||||
var expected int
|
var expected int
|
||||||
|
@ -662,24 +664,24 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) {
|
||||||
|
|
||||||
if err := d.Create(current, parent); err != nil {
|
if err := d.Create(current, parent); err != nil {
|
||||||
t.Logf("Current layer %d", i)
|
t.Logf("Current layer %d", i)
|
||||||
t.Fatal(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
point, err := d.Get(current, "")
|
point, err := d.Get(current, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("Current layer %d", i)
|
t.Logf("Current layer %d", i)
|
||||||
t.Fatal(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
f, err := os.Create(path.Join(point, current))
|
f, err := os.Create(path.Join(point, current))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Logf("Current layer %d", i)
|
t.Logf("Current layer %d", i)
|
||||||
t.Fatal(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
f.Close()
|
f.Close()
|
||||||
|
|
||||||
if i%10 == 0 {
|
if i%10 == 0 {
|
||||||
if err := os.Remove(path.Join(point, parent)); err != nil {
|
if err := os.Remove(path.Join(point, parent)); err != nil {
|
||||||
t.Logf("Current layer %d", i)
|
t.Logf("Current layer %d", i)
|
||||||
t.Fatal(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
expected--
|
expected--
|
||||||
}
|
}
|
||||||
|
@ -689,28 +691,30 @@ func testMountMoreThan42Layers(t *testing.T, mountPath string) {
|
||||||
// Perform the actual mount for the top most image
|
// Perform the actual mount for the top most image
|
||||||
point, err := d.Get(last, "")
|
point, err := d.Get(last, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
files, err := ioutil.ReadDir(point)
|
files, err := ioutil.ReadDir(point)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
if len(files) != expected {
|
if len(files) != expected {
|
||||||
t.Fatalf("Expected %d got %d", expected, len(files))
|
t.Errorf("Expected %d got %d", expected, len(files))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountMoreThan42Layers(t *testing.T) {
|
func TestMountMoreThan42Layers(t *testing.T) {
|
||||||
|
os.RemoveAll(tmpOuter)
|
||||||
testMountMoreThan42Layers(t, tmp)
|
testMountMoreThan42Layers(t, tmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMountMoreThan42LayersMatchingPathLength(t *testing.T) {
|
func TestMountMoreThan42LayersMatchingPathLength(t *testing.T) {
|
||||||
tmp := "aufs-tests"
|
defer os.RemoveAll(tmpOuter)
|
||||||
|
zeroes := "0"
|
||||||
for {
|
for {
|
||||||
// This finds a mount path so that when combined into aufs mount options
|
// This finds a mount path so that when combined into aufs mount options
|
||||||
// 4096 byte boundary would be in between the paths or in permission
|
// 4096 byte boundary would be in between the paths or in permission
|
||||||
// section. For '/tmp' it will use '/tmp/aufs-tests00000000/aufs'
|
// section. For '/tmp' it will use '/tmp/aufs-tests/00000000/aufs'
|
||||||
mountPath := path.Join(os.TempDir(), tmp, "aufs")
|
mountPath := path.Join(tmpOuter, zeroes, "aufs")
|
||||||
pathLength := 77 + len(mountPath)
|
pathLength := 77 + len(mountPath)
|
||||||
|
|
||||||
if mod := 4095 % pathLength; mod == 0 || mod > pathLength-2 {
|
if mod := 4095 % pathLength; mod == 0 || mod > pathLength-2 {
|
||||||
|
@ -718,6 +722,6 @@ func TestMountMoreThan42LayersMatchingPathLength(t *testing.T) {
|
||||||
testMountMoreThan42Layers(t, mountPath)
|
testMountMoreThan42Layers(t, mountPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
tmp += "0"
|
zeroes += "0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue