2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-07 11:30:49 +00:00

Merge pull request #1130 from middelink/fix-fuse-test

Fuse testing leaves test mountpoint around.
This commit is contained in:
Alexander Neumann 2017-07-24 21:26:05 +02:00
commit 608adf15a3
2 changed files with 13 additions and 18 deletions

View File

@ -6,7 +6,6 @@ package main
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -144,18 +143,15 @@ func TestMount(t *testing.T) {
}
withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) {
mountpoint, err := ioutil.TempDir(TestTempDir, "restic-test-mount-")
OK(t, err)
testRunInit(t, gopts)
repo, err := OpenRepository(gopts)
OK(t, err)
// 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"))
@ -165,7 +161,7 @@ func TestMount(t *testing.T) {
Assert(t, len(snapshotIDs) == 1,
"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
testRunBackup(t, []string{env.testdata}, BackupOptions{}, gopts)
@ -173,7 +169,7 @@ func TestMount(t *testing.T) {
Assert(t, len(snapshotIDs) == 2,
"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
bopts := BackupOptions{Parent: snapshotIDs[0].String()}
@ -182,7 +178,7 @@ func TestMount(t *testing.T) {
Assert(t, len(snapshotIDs) == 3,
"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)
OK(t, err)
mountpoint, err := ioutil.TempDir(TestTempDir, "restic-test-mount-")
OK(t, err)
ids := []restic.ID{
restic.TestParseID("280303689e5027328889a06d718b729e96a1ce6ae9ef8290bff550459ae611ee"),
restic.TestParseID("75ad6cdc0868e082f2596d5ab8705e9f7d87316f5bf5690385eeff8dbe49d9f5"),
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 {
base, cache, repo, testdata string
base, cache, repo, mountpoint, testdata string
}
// 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)
env := testEnvironment{
base: tempdir,
cache: filepath.Join(tempdir, "cache"),
repo: filepath.Join(tempdir, "repo"),
testdata: filepath.Join(tempdir, "testdata"),
base: tempdir,
cache: filepath.Join(tempdir, "cache"),
repo: filepath.Join(tempdir, "repo"),
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.cache, 0700))
OK(t, os.MkdirAll(env.repo, 0700))