@cryptotaxi247 / kubo / commits / 20f5cf7b2

fix fuse unmount test

Fuse unmount test uses ipfs instead of ipns, because offline nodes dont actually mount ipns. Factored out GOOS-aware function to determine unmount command in fuse/mount. fixed #5475 License: MIT Signed-off-by: Rob Deutsch <rdeutschob@gmail.com>

rob-deutsch committed Sep 16, 2018 at 14:54 UTC 20f5cf7b23abbe0f5a793e00eba289f67a51b776
2 files changed +24 -20
fuse/mount/mount.go
+16 -8
@@ -38,14 +38,9 @@ func ForceUnmount(m Mount) error {
38 point := m.MountPoint()
39 log.Warningf("Force-Unmounting %s...", point)
40
41 - var cmd *exec.Cmd
42 - switch runtime.GOOS {
43 - case "darwin":
44 - cmd = exec.Command("diskutil", "umount", "force", point)
45 - case "linux":
46 - cmd = exec.Command("fusermount", "-u", point)
47 - default:
48 - return fmt.Errorf("unmount: unimplemented")
41 + cmd, err := UnmountCmd(point)
42 + if err != nil {
43 + return err
44 }
45
46 errc := make(chan error, 1)
@@ -69,6 +64,19 @@ func ForceUnmount(m Mount) error {
64 }
65 }
66
67 +// UnmountCmd creates an exec.Cmd that is GOOS-specific
68 +// for unmount a FUSE mount
69 +func UnmountCmd(point string) (*exec.Cmd, error) {
70 + switch runtime.GOOS {
71 + case "darwin":
72 + return exec.Command("diskutil", "umount", "force", point), nil
73 + case "linux":
74 + return exec.Command("fusermount", "-u", point), nil
75 + default:
76 + return nil, fmt.Errorf("unmount: unimplemented")
77 + }
78 +}
79 +
80 // ForceUnmountManyTimes attempts to forcibly unmount a given mount,
81 // many times. It does so by calling diskutil or fusermount directly.
82 // Attempts a given number of times.
fuse/node/mount_test.go
+8 -12
@@ -5,7 +5,6 @@ package node
5 import (
6 "io/ioutil"
7 "os"
8 - "os/exec"
8 "testing"
9 "time"
10
@@ -77,24 +76,21 @@ func TestExternalUnmount(t *testing.T) {
76 }
77
78 // Run shell command to externally unmount the directory
80 - cmd := "fusermount"
81 - args := []string{"-u", ipnsDir}
82 - if err := exec.Command(cmd, args...).Run(); err != nil {
79 + cmd, err := mount.UnmountCmd(ipfsDir)
80 + if err != nil {
81 + t.Fatal(err)
82 + }
83 +
84 + if err := cmd.Run(); err != nil {
85 t.Fatal(err)
86 }
87
88 // TODO(noffle): it takes a moment for the goroutine that's running fs.Serve to be notified and do its cleanup.
89 time.Sleep(time.Millisecond * 100)
90
89 - // Attempt to unmount IPNS; check that it was already unmounted.
90 - err = node.Mounts.Ipns.Unmount()
91 - if err != mount.ErrNotMounted {
92 - t.Fatal("Unmount should have failed")
93 - }
94 -
91 // Attempt to unmount IPFS; it should unmount successfully.
92 err = node.Mounts.Ipfs.Unmount()
97 - if err != nil {
98 - t.Fatal(err)
93 + if err != mount.ErrNotMounted {
94 + t.Fatal("Unmount should have failed")
95 }
96 }