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
|
package btrfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
@ -141,26 +140,19 @@ func setupBtrfsLoopbackDevice(t *testing.T, mountPoint string) *testDevice {
|
||||||
t.Log("Temporary file created", file.Name())
|
t.Log("Temporary file created", file.Name())
|
||||||
|
|
||||||
// initialize file with 100 MiB
|
// initialize file with 100 MiB
|
||||||
zero := [mib]byte{}
|
if err := file.Truncate(100 << 20); err != nil {
|
||||||
for i := 0; i < 100; i++ {
|
t.Fatal(err)
|
||||||
_, err = file.Write(zero[:])
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal("Could not write to btrfs file", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
file.Close()
|
file.Close()
|
||||||
|
|
||||||
// create device
|
// create device
|
||||||
losetup := exec.Command("losetup", "--find", "--show", file.Name())
|
losetup := exec.Command("losetup", "--find", "--show", file.Name())
|
||||||
var stdout, stderr bytes.Buffer
|
p, err := losetup.Output()
|
||||||
losetup.Stdout = &stdout
|
|
||||||
losetup.Stderr = &stderr
|
|
||||||
err = losetup.Run()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(stderr.String())
|
t.Fatal(err)
|
||||||
t.Fatal("Could not run losetup", err)
|
|
||||||
}
|
}
|
||||||
deviceName := strings.TrimSpace(stdout.String())
|
|
||||||
|
deviceName := strings.TrimSpace(string(p))
|
||||||
t.Log("Created loop device", deviceName)
|
t.Log("Created loop device", deviceName)
|
||||||
|
|
||||||
// format
|
// format
|
||||||
|
|
Loading…
Reference in a new issue