Skip to content

Commit 9a6f06d

Browse files
committed
unit-test: use /smallfs when non-root
1 parent 67f6a0e commit 9a6f06d

1 file changed

Lines changed: 42 additions & 39 deletions

File tree

files/public_test.go

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -452,35 +452,35 @@ func (s *DiskFullSuite) SetUpTest(c *C) {
452452
if runtime.GOOS != "linux" {
453453
c.Skip("disk full tests only run on Linux")
454454
}
455-
if os.Geteuid() != 0 {
456-
c.Skip("disk full tests require root privileges")
457-
}
458455

459456
s.root = c.MkDir()
460457
}
461458

462459
func (s *DiskFullSuite) TestPutFileOutOfSpace(c *C) {
463-
mountPoint := filepath.Join(s.root, "smallfs")
464-
err := os.MkdirAll(mountPoint, 0777)
465-
c.Assert(err, IsNil)
466-
fsImage := filepath.Join(s.root, "small.img")
467-
cmd := exec.Command("dd", "if=/dev/zero", "of="+fsImage, "bs=1M", "count=1")
468-
err = cmd.Run()
469-
c.Assert(err, IsNil)
470-
cmd = exec.Command("mkfs.ext4", "-F", fsImage)
471-
err = cmd.Run()
472-
c.Assert(err, IsNil)
473-
cmd = exec.Command("mount", "-o", "loop", fsImage, mountPoint)
474-
err = cmd.Run()
475-
c.Assert(err, IsNil)
476-
defer func() {
477-
_ = exec.Command("umount", mountPoint).Run()
478-
}()
460+
mountPoint := "/smallfs"
461+
if os.Geteuid() == 0 {
462+
mountPoint = filepath.Join(s.root, "smallfs")
463+
err := os.MkdirAll(mountPoint, 0777)
464+
c.Assert(err, IsNil)
465+
fsImage := filepath.Join(s.root, "small.img")
466+
cmd := exec.Command("dd", "if=/dev/zero", "of="+fsImage, "bs=1M", "count=1")
467+
err = cmd.Run()
468+
c.Assert(err, IsNil)
469+
cmd = exec.Command("mkfs.ext4", "-F", fsImage)
470+
err = cmd.Run()
471+
c.Assert(err, IsNil)
472+
cmd = exec.Command("mount", "-o", "loop", fsImage, mountPoint)
473+
err = cmd.Run()
474+
c.Assert(err, IsNil)
475+
defer func() {
476+
_ = exec.Command("umount", mountPoint).Run()
477+
}()
478+
}
479479

480480
storage := NewPublishedStorage(mountPoint, "", "")
481481
largeFile := filepath.Join(s.root, "largefile")
482-
cmd = exec.Command("dd", "if=/dev/zero", "of="+largeFile, "bs=1M", "count=2")
483-
err = cmd.Run()
482+
cmd := exec.Command("dd", "if=/dev/zero", "of="+largeFile, "bs=1M", "count=2")
483+
err := cmd.Run()
484484
c.Assert(err, IsNil)
485485

486486
err = storage.PutFile("testfile", largeFile)
@@ -491,25 +491,28 @@ func (s *DiskFullSuite) TestPutFileOutOfSpace(c *C) {
491491
}
492492

493493
func (s *DiskFullSuite) TestLinkFromPoolCopyOutOfSpace(c *C) {
494-
mountPoint := filepath.Join(s.root, "smallfs")
495-
err := os.MkdirAll(mountPoint, 0777)
496-
c.Assert(err, IsNil)
497-
fsImage := filepath.Join(s.root, "small.img")
494+
mountPoint := "/smallfs"
495+
if os.Geteuid() == 0 {
496+
mountPoint = filepath.Join(s.root, "smallfs")
497+
err := os.MkdirAll(mountPoint, 0777)
498+
c.Assert(err, IsNil)
499+
fsImage := filepath.Join(s.root, "small.img")
498500

499-
cmd := exec.Command("dd", "if=/dev/zero", "of="+fsImage, "bs=1M", "count=1")
500-
err = cmd.Run()
501-
c.Assert(err, IsNil)
501+
cmd := exec.Command("dd", "if=/dev/zero", "of="+fsImage, "bs=1M", "count=1")
502+
err = cmd.Run()
503+
c.Assert(err, IsNil)
502504

503-
cmd = exec.Command("mkfs.ext4", "-F", fsImage)
504-
err = cmd.Run()
505-
c.Assert(err, IsNil)
505+
cmd = exec.Command("mkfs.ext4", "-F", fsImage)
506+
err = cmd.Run()
507+
c.Assert(err, IsNil)
506508

507-
cmd = exec.Command("mount", "-o", "loop", fsImage, mountPoint)
508-
err = cmd.Run()
509-
c.Assert(err, IsNil)
510-
defer func() {
511-
_ = exec.Command("umount", mountPoint).Run()
512-
}()
509+
cmd = exec.Command("mount", "-o", "loop", fsImage, mountPoint)
510+
err = cmd.Run()
511+
c.Assert(err, IsNil)
512+
defer func() {
513+
_ = exec.Command("umount", mountPoint).Run()
514+
}()
515+
}
513516

514517
storage := NewPublishedStorage(mountPoint, "copy", "")
515518

@@ -518,8 +521,8 @@ func (s *DiskFullSuite) TestLinkFromPoolCopyOutOfSpace(c *C) {
518521
cs := NewMockChecksumStorage()
519522

520523
largeFile := filepath.Join(s.root, "package.deb")
521-
cmd = exec.Command("dd", "if=/dev/zero", "of="+largeFile, "bs=1M", "count=2")
522-
err = cmd.Run()
524+
cmd := exec.Command("dd", "if=/dev/zero", "of="+largeFile, "bs=1M", "count=2")
525+
err := cmd.Run()
523526
c.Assert(err, IsNil)
524527

525528
sourceChecksum, err := utils.ChecksumsForFile(largeFile)

0 commit comments

Comments
 (0)