mirror of
https://github.com/octoleo/restic.git
synced 2024-11-02 11:46:36 +00:00
Merge pull request #1130 from middelink/fix-fuse-test
Fuse testing leaves test mountpoint around.
This commit is contained in:
commit
608adf15a3
@ -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)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
@ -187,8 +187,10 @@ func withTestEnvironment(t testing.TB, f func(*testEnvironment, GlobalOptions))
|
|||||||
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))
|
||||||
|
Loading…
Reference in New Issue
Block a user