Merge pull request #9261 from unclejack/fix_test_tmp_cleanup
fix cleanup of /tmp in tests
This commit is contained in:
commit
0d5323cb60
5 changed files with 16 additions and 7 deletions
|
@ -742,17 +742,20 @@ func NewTempArchive(src Archive, dir string) (*TempArchive, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
size := st.Size()
|
size := st.Size()
|
||||||
return &TempArchive{f, size}, nil
|
return &TempArchive{f, size, 0}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type TempArchive struct {
|
type TempArchive struct {
|
||||||
*os.File
|
*os.File
|
||||||
Size int64 // Pre-computed from Stat().Size() as a convenience
|
Size int64 // Pre-computed from Stat().Size() as a convenience
|
||||||
|
read int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (archive *TempArchive) Read(data []byte) (int, error) {
|
func (archive *TempArchive) Read(data []byte) (int, error) {
|
||||||
n, err := archive.File.Read(data)
|
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())
|
os.Remove(archive.File.Name())
|
||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
|
|
|
@ -46,6 +46,7 @@ func TestFollowSymLinkUnderLinkedDir(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
os.Mkdir(filepath.Join(dir, "realdir"), 0700)
|
os.Mkdir(filepath.Join(dir, "realdir"), 0700)
|
||||||
os.Symlink("realdir", filepath.Join(dir, "linkdir"))
|
os.Symlink("realdir", filepath.Join(dir, "linkdir"))
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestLstat(t *testing.T) {
|
func TestLstat(t *testing.T) {
|
||||||
file, invalid, _ := prepareFiles(t)
|
file, invalid, _, dir := prepareFiles(t)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
statFile, err := Lstat(file)
|
statFile, err := Lstat(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
"syscall"
|
"syscall"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFromStatT(t *testing.T) {
|
func TestFromStatT(t *testing.T) {
|
||||||
file, _, _ := prepareFiles(t)
|
file, _, _, dir := prepareFiles(t)
|
||||||
|
defer os.RemoveAll(dir)
|
||||||
|
|
||||||
stat := &syscall.Stat_t{}
|
stat := &syscall.Stat_t{}
|
||||||
err := syscall.Lstat(file, stat)
|
err := syscall.Lstat(file, stat)
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"testing"
|
"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")
|
dir, err := ioutil.TempDir("", "docker-system-test")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -26,11 +26,12 @@ func prepareFiles(t *testing.T) (string, string, string) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return file, invalid, symlink
|
return file, invalid, symlink, dir
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLUtimesNano(t *testing.T) {
|
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)
|
before, err := os.Stat(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue