snapshot/btrfs: simplify test setup
After reviewing this closer, we removed a few buffers in favor `(*exec.Command).Output` and simplified the loop file creation method to just use `(*os.File).Truncate`. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
8fdccbf8e9
commit
5922756d8b
1 changed files with 6 additions and 14 deletions
|
@ -1,7 +1,6 @@
|
|||
package btrfs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -141,26 +140,19 @@ func setupBtrfsLoopbackDevice(t *testing.T, mountPoint string) *testDevice {
|
|||
t.Log("Temporary file created", file.Name())
|
||||
|
||||
// initialize file with 100 MiB
|
||||
zero := [mib]byte{}
|
||||
for i := 0; i < 100; i++ {
|
||||
_, err = file.Write(zero[:])
|
||||
if err != nil {
|
||||
t.Fatal("Could not write to btrfs file", err)
|
||||
}
|
||||
if err := file.Truncate(100 << 20); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
file.Close()
|
||||
|
||||
// create device
|
||||
losetup := exec.Command("losetup", "--find", "--show", file.Name())
|
||||
var stdout, stderr bytes.Buffer
|
||||
losetup.Stdout = &stdout
|
||||
losetup.Stderr = &stderr
|
||||
err = losetup.Run()
|
||||
p, err := losetup.Output()
|
||||
if err != nil {
|
||||
t.Log(stderr.String())
|
||||
t.Fatal("Could not run losetup", err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
deviceName := strings.TrimSpace(stdout.String())
|
||||
|
||||
deviceName := strings.TrimSpace(string(p))
|
||||
t.Log("Created loop device", deviceName)
|
||||
|
||||
// format
|
||||
|
|
Loading…
Reference in a new issue