Merge pull request #9261 from unclejack/fix_test_tmp_cleanup

fix cleanup of /tmp in tests
This commit is contained in:
Alexander Morozov 2014-11-21 08:48:04 -08:00
commit 0d5323cb60
5 changed files with 16 additions and 7 deletions

View file

@ -742,17 +742,20 @@ func NewTempArchive(src Archive, dir string) (*TempArchive, error) {
return nil, err
}
size := st.Size()
return &TempArchive{f, size}, nil
return &TempArchive{f, size, 0}, nil
}
type TempArchive struct {
*os.File
Size int64 // Pre-computed from Stat().Size() as a convenience
read int64
}
func (archive *TempArchive) Read(data []byte) (int, error) {
n, err := archive.File.Read(data)
if err != nil {
archive.read += int64(n)
if err != nil || archive.read == archive.Size {
archive.File.Close()
os.Remove(archive.File.Name())
}
return n, err

View file

@ -46,6 +46,7 @@ func TestFollowSymLinkUnderLinkedDir(t *testing.T) {
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(dir)
os.Mkdir(filepath.Join(dir, "realdir"), 0700)
os.Symlink("realdir", filepath.Join(dir, "linkdir"))

View file

@ -1,11 +1,13 @@
package system
import (
"os"
"testing"
)
func TestLstat(t *testing.T) {
file, invalid, _ := prepareFiles(t)
file, invalid, _, dir := prepareFiles(t)
defer os.RemoveAll(dir)
statFile, err := Lstat(file)
if err != nil {

View file

@ -1,12 +1,14 @@
package system
import (
"os"
"syscall"
"testing"
)
func TestFromStatT(t *testing.T) {
file, _, _ := prepareFiles(t)
file, _, _, dir := prepareFiles(t)
defer os.RemoveAll(dir)
stat := &syscall.Stat_t{}
err := syscall.Lstat(file, stat)

View file

@ -8,7 +8,7 @@ import (
"testing"
)
func prepareFiles(t *testing.T) (string, string, string) {
func prepareFiles(t *testing.T) (string, string, string, string) {
dir, err := ioutil.TempDir("", "docker-system-test")
if err != nil {
t.Fatal(err)
@ -26,11 +26,12 @@ func prepareFiles(t *testing.T) (string, string, string) {
t.Fatal(err)
}
return file, invalid, symlink
return file, invalid, symlink, dir
}
func TestLUtimesNano(t *testing.T) {
file, invalid, symlink := prepareFiles(t)
file, invalid, symlink, dir := prepareFiles(t)
defer os.RemoveAll(dir)
before, err := os.Stat(file)
if err != nil {