forked from TrueCloudLab/restic
Unmount and remove directory for mount in tests
This commit is contained in:
parent
e44716381c
commit
3767eb2675
3 changed files with 34 additions and 23 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
type CmdMount struct {
|
||||
global *GlobalOptions
|
||||
ready chan struct{}
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -24,6 +25,7 @@ func init() {
|
|||
&CmdMount{
|
||||
global: &globalOpts,
|
||||
ready: make(chan struct{}, 1),
|
||||
done: make(chan struct{}),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -78,11 +80,25 @@ func (cmd CmdMount) Execute(args []string) error {
|
|||
|
||||
cmd.ready <- struct{}{}
|
||||
|
||||
err = fs.Serve(c, &root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
errServe := make(chan error)
|
||||
go func() {
|
||||
err = fs.Serve(c, &root)
|
||||
if err != nil {
|
||||
errServe <- err
|
||||
}
|
||||
|
||||
<-c.Ready
|
||||
return c.MountError
|
||||
<-c.Ready
|
||||
errServe <- c.MountError
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-errServe:
|
||||
return err
|
||||
case <-cmd.done:
|
||||
err := c.Close()
|
||||
if err != nil {
|
||||
cmd.global.Printf("Error closing fuse connection: %s\n", err)
|
||||
}
|
||||
return systemFuse.Unmount(mountpoint)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"bazil.org/fuse"
|
||||
|
||||
"github.com/restic/restic"
|
||||
"github.com/restic/restic/backend"
|
||||
"github.com/restic/restic/repository"
|
||||
|
@ -53,6 +51,15 @@ func waitForMount(dir string) error {
|
|||
|
||||
return fmt.Errorf("subdir %q of dir %s never appeared", mountTestSubdir, dir)
|
||||
}
|
||||
|
||||
func cmdMount(t testing.TB, global GlobalOptions, dir string, ready, done chan struct{}) {
|
||||
cmd := &CmdMount{global: &global, ready: ready, done: done}
|
||||
OK(t, cmd.Execute([]string{dir}))
|
||||
if TestCleanup {
|
||||
OK(t, os.RemoveAll(dir))
|
||||
}
|
||||
}
|
||||
|
||||
func TestMount(t *testing.T) {
|
||||
if !RunFuseTest {
|
||||
t.Skip("Skipping fuse tests")
|
||||
|
@ -97,17 +104,10 @@ func TestMount(t *testing.T) {
|
|||
OK(t, os.RemoveAll(mountpoint))
|
||||
|
||||
ready := make(chan struct{}, 1)
|
||||
go cmdMount(t, global, mountpoint, ready)
|
||||
done := make(chan struct{})
|
||||
go cmdMount(t, global, mountpoint, ready, done)
|
||||
<-ready
|
||||
|
||||
defer func() {
|
||||
err := fuse.Unmount(mountpoint)
|
||||
OK(t, err)
|
||||
if TestCleanup {
|
||||
err = os.RemoveAll(mountpoint)
|
||||
OK(t, err)
|
||||
}
|
||||
}()
|
||||
defer close(done)
|
||||
OK(t, waitForMount(mountpoint))
|
||||
|
||||
mountpointDir, err := os.Open(mountpoint)
|
||||
|
|
|
@ -73,11 +73,6 @@ func cmdCheck(t testing.TB, global GlobalOptions) {
|
|||
OK(t, cmd.Execute(nil))
|
||||
}
|
||||
|
||||
func cmdMount(t testing.TB, global GlobalOptions, dir string, ready chan struct{}) {
|
||||
cmd := &CmdMount{global: &global, ready: ready}
|
||||
OK(t, cmd.Execute([]string{dir}))
|
||||
}
|
||||
|
||||
func TestBackup(t *testing.T) {
|
||||
withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) {
|
||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
||||
|
|
Loading…
Reference in a new issue