mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-06-04 05:10:40 +00:00
unit-test: use /smallfs when non-root
This commit is contained in:
+42
-39
@@ -452,35 +452,35 @@ func (s *DiskFullSuite) SetUpTest(c *C) {
|
|||||||
if runtime.GOOS != "linux" {
|
if runtime.GOOS != "linux" {
|
||||||
c.Skip("disk full tests only run on Linux")
|
c.Skip("disk full tests only run on Linux")
|
||||||
}
|
}
|
||||||
if os.Geteuid() != 0 {
|
|
||||||
c.Skip("disk full tests require root privileges")
|
|
||||||
}
|
|
||||||
|
|
||||||
s.root = c.MkDir()
|
s.root = c.MkDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DiskFullSuite) TestPutFileOutOfSpace(c *C) {
|
func (s *DiskFullSuite) TestPutFileOutOfSpace(c *C) {
|
||||||
mountPoint := filepath.Join(s.root, "smallfs")
|
mountPoint := "/smallfs"
|
||||||
err := os.MkdirAll(mountPoint, 0777)
|
if os.Geteuid() == 0 {
|
||||||
c.Assert(err, IsNil)
|
mountPoint = filepath.Join(s.root, "smallfs")
|
||||||
fsImage := filepath.Join(s.root, "small.img")
|
err := os.MkdirAll(mountPoint, 0777)
|
||||||
cmd := exec.Command("dd", "if=/dev/zero", "of="+fsImage, "bs=1M", "count=1")
|
c.Assert(err, IsNil)
|
||||||
err = cmd.Run()
|
fsImage := filepath.Join(s.root, "small.img")
|
||||||
c.Assert(err, IsNil)
|
cmd := exec.Command("dd", "if=/dev/zero", "of="+fsImage, "bs=1M", "count=1")
|
||||||
cmd = exec.Command("mkfs.ext4", "-F", fsImage)
|
err = cmd.Run()
|
||||||
err = cmd.Run()
|
c.Assert(err, IsNil)
|
||||||
c.Assert(err, IsNil)
|
cmd = exec.Command("mkfs.ext4", "-F", fsImage)
|
||||||
cmd = exec.Command("mount", "-o", "loop", fsImage, mountPoint)
|
err = cmd.Run()
|
||||||
err = cmd.Run()
|
c.Assert(err, IsNil)
|
||||||
c.Assert(err, IsNil)
|
cmd = exec.Command("mount", "-o", "loop", fsImage, mountPoint)
|
||||||
defer func() {
|
err = cmd.Run()
|
||||||
_ = exec.Command("umount", mountPoint).Run()
|
c.Assert(err, IsNil)
|
||||||
}()
|
defer func() {
|
||||||
|
_ = exec.Command("umount", mountPoint).Run()
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
storage := NewPublishedStorage(mountPoint, "", "")
|
storage := NewPublishedStorage(mountPoint, "", "")
|
||||||
largeFile := filepath.Join(s.root, "largefile")
|
largeFile := filepath.Join(s.root, "largefile")
|
||||||
cmd = exec.Command("dd", "if=/dev/zero", "of="+largeFile, "bs=1M", "count=2")
|
cmd := exec.Command("dd", "if=/dev/zero", "of="+largeFile, "bs=1M", "count=2")
|
||||||
err = cmd.Run()
|
err := cmd.Run()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
err = storage.PutFile("testfile", largeFile)
|
err = storage.PutFile("testfile", largeFile)
|
||||||
@@ -491,25 +491,28 @@ func (s *DiskFullSuite) TestPutFileOutOfSpace(c *C) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *DiskFullSuite) TestLinkFromPoolCopyOutOfSpace(c *C) {
|
func (s *DiskFullSuite) TestLinkFromPoolCopyOutOfSpace(c *C) {
|
||||||
mountPoint := filepath.Join(s.root, "smallfs")
|
mountPoint := "/smallfs"
|
||||||
err := os.MkdirAll(mountPoint, 0777)
|
if os.Geteuid() == 0 {
|
||||||
c.Assert(err, IsNil)
|
mountPoint = filepath.Join(s.root, "smallfs")
|
||||||
fsImage := filepath.Join(s.root, "small.img")
|
err := os.MkdirAll(mountPoint, 0777)
|
||||||
|
c.Assert(err, IsNil)
|
||||||
|
fsImage := filepath.Join(s.root, "small.img")
|
||||||
|
|
||||||
cmd := exec.Command("dd", "if=/dev/zero", "of="+fsImage, "bs=1M", "count=1")
|
cmd := exec.Command("dd", "if=/dev/zero", "of="+fsImage, "bs=1M", "count=1")
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
cmd = exec.Command("mkfs.ext4", "-F", fsImage)
|
cmd = exec.Command("mkfs.ext4", "-F", fsImage)
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
cmd = exec.Command("mount", "-o", "loop", fsImage, mountPoint)
|
cmd = exec.Command("mount", "-o", "loop", fsImage, mountPoint)
|
||||||
err = cmd.Run()
|
err = cmd.Run()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = exec.Command("umount", mountPoint).Run()
|
_ = exec.Command("umount", mountPoint).Run()
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
storage := NewPublishedStorage(mountPoint, "copy", "")
|
storage := NewPublishedStorage(mountPoint, "copy", "")
|
||||||
|
|
||||||
@@ -518,8 +521,8 @@ func (s *DiskFullSuite) TestLinkFromPoolCopyOutOfSpace(c *C) {
|
|||||||
cs := NewMockChecksumStorage()
|
cs := NewMockChecksumStorage()
|
||||||
|
|
||||||
largeFile := filepath.Join(s.root, "package.deb")
|
largeFile := filepath.Join(s.root, "package.deb")
|
||||||
cmd = exec.Command("dd", "if=/dev/zero", "of="+largeFile, "bs=1M", "count=2")
|
cmd := exec.Command("dd", "if=/dev/zero", "of="+largeFile, "bs=1M", "count=2")
|
||||||
err = cmd.Run()
|
err := cmd.Run()
|
||||||
c.Assert(err, IsNil)
|
c.Assert(err, IsNil)
|
||||||
|
|
||||||
sourceChecksum, err := utils.ChecksumsForFile(largeFile)
|
sourceChecksum, err := utils.ChecksumsForFile(largeFile)
|
||||||
|
|||||||
Reference in New Issue
Block a user