1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2024-12-23 16:26:11 +00:00

Fuse testing leaves test mountpoint around. Move it under the testing tree which is removed after each test.

This commit is contained in:
Pauline Middelink 2017-07-24 20:28:01 +02:00
parent 23c903074c
commit 1717391f6c
2 changed files with 13 additions and 18 deletions

View file

@ -6,7 +6,6 @@ package main
import ( import (
"context" "context"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
@ -144,18 +143,15 @@ func TestMount(t *testing.T) {
} }
withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) { withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) {
mountpoint, err := ioutil.TempDir(TestTempDir, "restic-test-mount-")
OK(t, err)
testRunInit(t, gopts) testRunInit(t, gopts)
repo, err := OpenRepository(gopts) repo, err := OpenRepository(gopts)
OK(t, err) OK(t, err)
// We remove the mountpoint now to check that cmdMount creates it // We remove the mountpoint now to check that cmdMount creates it
RemoveAll(t, mountpoint) RemoveAll(t, env.mountpoint)
checkSnapshots(t, gopts, repo, mountpoint, env.repo, []restic.ID{}) checkSnapshots(t, gopts, repo, env.mountpoint, env.repo, []restic.ID{})
SetupTarTestFixture(t, env.testdata, filepath.Join("testdata", "backup-data.tar.gz")) SetupTarTestFixture(t, env.testdata, filepath.Join("testdata", "backup-data.tar.gz"))
@ -165,7 +161,7 @@ func TestMount(t *testing.T) {
Assert(t, len(snapshotIDs) == 1, Assert(t, len(snapshotIDs) == 1,
"expected one snapshot, got %v", snapshotIDs) "expected one snapshot, got %v", snapshotIDs)
checkSnapshots(t, gopts, repo, mountpoint, env.repo, snapshotIDs) checkSnapshots(t, gopts, repo, env.mountpoint, env.repo, snapshotIDs)
// second backup, implicit incremental // second backup, implicit incremental
testRunBackup(t, []string{env.testdata}, BackupOptions{}, gopts) testRunBackup(t, []string{env.testdata}, BackupOptions{}, gopts)
@ -173,7 +169,7 @@ func TestMount(t *testing.T) {
Assert(t, len(snapshotIDs) == 2, Assert(t, len(snapshotIDs) == 2,
"expected two snapshots, got %v", snapshotIDs) "expected two snapshots, got %v", snapshotIDs)
checkSnapshots(t, gopts, repo, mountpoint, env.repo, snapshotIDs) checkSnapshots(t, gopts, repo, env.mountpoint, env.repo, snapshotIDs)
// third backup, explicit incremental // third backup, explicit incremental
bopts := BackupOptions{Parent: snapshotIDs[0].String()} bopts := BackupOptions{Parent: snapshotIDs[0].String()}
@ -182,7 +178,7 @@ func TestMount(t *testing.T) {
Assert(t, len(snapshotIDs) == 3, Assert(t, len(snapshotIDs) == 3,
"expected three snapshots, got %v", snapshotIDs) "expected three snapshots, got %v", snapshotIDs)
checkSnapshots(t, gopts, repo, mountpoint, env.repo, snapshotIDs) checkSnapshots(t, gopts, repo, env.mountpoint, env.repo, snapshotIDs)
}) })
} }
@ -197,15 +193,12 @@ func TestMountSameTimestamps(t *testing.T) {
repo, err := OpenRepository(gopts) repo, err := OpenRepository(gopts)
OK(t, err) OK(t, err)
mountpoint, err := ioutil.TempDir(TestTempDir, "restic-test-mount-")
OK(t, err)
ids := []restic.ID{ ids := []restic.ID{
restic.TestParseID("280303689e5027328889a06d718b729e96a1ce6ae9ef8290bff550459ae611ee"), restic.TestParseID("280303689e5027328889a06d718b729e96a1ce6ae9ef8290bff550459ae611ee"),
restic.TestParseID("75ad6cdc0868e082f2596d5ab8705e9f7d87316f5bf5690385eeff8dbe49d9f5"), restic.TestParseID("75ad6cdc0868e082f2596d5ab8705e9f7d87316f5bf5690385eeff8dbe49d9f5"),
restic.TestParseID("5fd0d8b2ef0fa5d23e58f1e460188abb0f525c0f0c4af8365a1280c807a80a1b"), restic.TestParseID("5fd0d8b2ef0fa5d23e58f1e460188abb0f525c0f0c4af8365a1280c807a80a1b"),
} }
checkSnapshots(t, gopts, repo, mountpoint, env.repo, ids) checkSnapshots(t, gopts, repo, env.mountpoint, env.repo, ids)
}) })
} }

View file

@ -167,7 +167,7 @@ func dirStats(dir string) (stat dirStat) {
} }
type testEnvironment struct { type testEnvironment struct {
base, cache, repo, testdata string base, cache, repo, mountpoint, testdata string
} }
// withTestEnvironment creates a test environment and calls f with it. After f has // withTestEnvironment creates a test environment and calls f with it. After f has
@ -183,12 +183,14 @@ func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions))
OK(t, err) OK(t, err)
env := testEnvironment{ env := testEnvironment{
base: tempdir, base: tempdir,
cache: filepath.Join(tempdir, "cache"), cache: filepath.Join(tempdir, "cache"),
repo: filepath.Join(tempdir, "repo"), repo: filepath.Join(tempdir, "repo"),
testdata: filepath.Join(tempdir, "testdata"), testdata: filepath.Join(tempdir, "testdata"),
mountpoint: filepath.Join(tempdir, "mount"),
} }
OK(t, os.MkdirAll(env.mountpoint, 0700))
OK(t, os.MkdirAll(env.testdata, 0700)) OK(t, os.MkdirAll(env.testdata, 0700))
OK(t, os.MkdirAll(env.cache, 0700)) OK(t, os.MkdirAll(env.cache, 0700))
OK(t, os.MkdirAll(env.repo, 0700)) OK(t, os.MkdirAll(env.repo, 0700))