Merge pull request #533 from stevvooe/simplify-btrfs-test-setup
snapshot/btrfs: simplify test setup
This commit is contained in:
commit
54b804c601
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