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 {
|
type CmdMount struct {
|
||||||
global *GlobalOptions
|
global *GlobalOptions
|
||||||
ready chan struct{}
|
ready chan struct{}
|
||||||
|
done chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -24,6 +25,7 @@ func init() {
|
||||||
&CmdMount{
|
&CmdMount{
|
||||||
global: &globalOpts,
|
global: &globalOpts,
|
||||||
ready: make(chan struct{}, 1),
|
ready: make(chan struct{}, 1),
|
||||||
|
done: make(chan struct{}),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -78,11 +80,25 @@ func (cmd CmdMount) Execute(args []string) error {
|
||||||
|
|
||||||
cmd.ready <- struct{}{}
|
cmd.ready <- struct{}{}
|
||||||
|
|
||||||
err = fs.Serve(c, &root)
|
errServe := make(chan error)
|
||||||
if err != nil {
|
go func() {
|
||||||
return err
|
err = fs.Serve(c, &root)
|
||||||
}
|
if err != nil {
|
||||||
|
errServe <- err
|
||||||
|
}
|
||||||
|
|
||||||
<-c.Ready
|
<-c.Ready
|
||||||
return c.MountError
|
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"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"bazil.org/fuse"
|
|
||||||
|
|
||||||
"github.com/restic/restic"
|
"github.com/restic/restic"
|
||||||
"github.com/restic/restic/backend"
|
"github.com/restic/restic/backend"
|
||||||
"github.com/restic/restic/repository"
|
"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)
|
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) {
|
func TestMount(t *testing.T) {
|
||||||
if !RunFuseTest {
|
if !RunFuseTest {
|
||||||
t.Skip("Skipping fuse tests")
|
t.Skip("Skipping fuse tests")
|
||||||
|
@ -97,17 +104,10 @@ func TestMount(t *testing.T) {
|
||||||
OK(t, os.RemoveAll(mountpoint))
|
OK(t, os.RemoveAll(mountpoint))
|
||||||
|
|
||||||
ready := make(chan struct{}, 1)
|
ready := make(chan struct{}, 1)
|
||||||
go cmdMount(t, global, mountpoint, ready)
|
done := make(chan struct{})
|
||||||
|
go cmdMount(t, global, mountpoint, ready, done)
|
||||||
<-ready
|
<-ready
|
||||||
|
defer close(done)
|
||||||
defer func() {
|
|
||||||
err := fuse.Unmount(mountpoint)
|
|
||||||
OK(t, err)
|
|
||||||
if TestCleanup {
|
|
||||||
err = os.RemoveAll(mountpoint)
|
|
||||||
OK(t, err)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
OK(t, waitForMount(mountpoint))
|
OK(t, waitForMount(mountpoint))
|
||||||
|
|
||||||
mountpointDir, err := os.Open(mountpoint)
|
mountpointDir, err := os.Open(mountpoint)
|
||||||
|
|
|
@ -73,11 +73,6 @@ func cmdCheck(t testing.TB, global GlobalOptions) {
|
||||||
OK(t, cmd.Execute(nil))
|
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) {
|
func TestBackup(t *testing.T) {
|
||||||
withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) {
|
withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) {
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
||||||
|
|
Loading…
Reference in a new issue