diff --git a/.travis.yml b/.travis.yml index c675033a9..642f0ec5d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,7 @@ os: - linux - osx -env: GOX_OS="linux darwin openbsd freebsd" GOX_ARCH="386 amd64 arm" +env: GOX_OS="linux darwin openbsd freebsd" GOX_ARCH="386 amd64 arm" RESTIC_TEST_FUSE="0" notifications: irc: diff --git a/cmd/restic/cmd_mount.go b/cmd/restic/cmd_mount.go index 96241be2d..62f8a5efa 100644 --- a/cmd/restic/cmd_mount.go +++ b/cmd/restic/cmd_mount.go @@ -1,3 +1,5 @@ +// +build !openbsd + package main import ( diff --git a/cmd/restic/integration_fuse_test.go b/cmd/restic/integration_fuse_test.go new file mode 100644 index 000000000..f12b714e7 --- /dev/null +++ b/cmd/restic/integration_fuse_test.go @@ -0,0 +1,101 @@ +// +build !openbsd + +package main + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" + "time" + + "github.com/restic/restic" + "github.com/restic/restic/backend" + "github.com/restic/restic/repository" + . "github.com/restic/restic/test" +) + +func TestMount(t *testing.T) { + if !RunFuseTest { + t.Skip("Skipping fuse tests") + } + + checkSnapshots := func(repo *repository.Repository, mountpoint string, snapshotIDs []backend.ID) { + stSnapshots, err := os.Open(filepath.Join(mountpoint, "snapshots")) + OK(t, err) + namesInSnapshots, err := stSnapshots.Readdirnames(-1) + OK(t, err) + Assert(t, + len(namesInSnapshots) == len(snapshotIDs), + "Invalid number of snapshots: expected %d, got %d", len(snapshotIDs), len(namesInSnapshots)) + + for i, id := range snapshotIDs { + snapshot, err := restic.LoadSnapshot(repo, id) + OK(t, err) + Assert(t, + namesInSnapshots[i] == snapshot.Time.Format(time.RFC3339), + "Invalid snapshot folder name: expected %s, got %s", snapshot.Time.Format(time.RFC3339), namesInSnapshots[i]) + } + OK(t, stSnapshots.Close()) + } + + withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) { + cmdInit(t, global) + repo, err := global.OpenRepository() + OK(t, err) + + mountpoint, err := ioutil.TempDir(TestTempDir, "restic-test-mount-") + OK(t, err) + + // We remove the mountpoint now to check that cmdMount creates it + OK(t, os.RemoveAll(mountpoint)) + + ready := make(chan struct{}, 1) + go cmdMount(t, global, mountpoint, ready) + <-ready + + stMountPoint, err := os.Open(mountpoint) + OK(t, err) + names, err := stMountPoint.Readdirnames(-1) + OK(t, err) + Assert(t, len(names) == 1 && names[0] == "snapshots", "expected the snapshots directory to exist") + OK(t, stMountPoint.Close()) + + checkSnapshots(repo, mountpoint, []backend.ID{}) + + datafile := filepath.Join("testdata", "backup-data.tar.gz") + fd, err := os.Open(datafile) + if os.IsNotExist(err) { + t.Skipf("unable to find data file %q, skipping", datafile) + return + } + OK(t, err) + OK(t, fd.Close()) + + SetupTarTestFixture(t, env.testdata, datafile) + + // first backup + cmdBackup(t, global, []string{env.testdata}, nil) + snapshotIDs := cmdList(t, global, "snapshots") + Assert(t, len(snapshotIDs) == 1, + "expected one snapshot, got %v", snapshotIDs) + + checkSnapshots(repo, mountpoint, snapshotIDs) + + // second backup, implicit incremental + cmdBackup(t, global, []string{env.testdata}, nil) + snapshotIDs = cmdList(t, global, "snapshots") + Assert(t, len(snapshotIDs) == 2, + "expected two snapshots, got %v", snapshotIDs) + + checkSnapshots(repo, mountpoint, snapshotIDs) + + // third backup, explicit incremental + cmdBackup(t, global, []string{env.testdata}, snapshotIDs[0]) + snapshotIDs = cmdList(t, global, "snapshots") + Assert(t, len(snapshotIDs) == 3, + "expected three snapshots, got %v", snapshotIDs) + + checkSnapshots(repo, mountpoint, snapshotIDs) + }) +} diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 9a08cd932..4bbad4861 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -14,10 +14,8 @@ import ( "testing" "time" - "github.com/restic/restic" "github.com/restic/restic/backend" "github.com/restic/restic/debug" - "github.com/restic/restic/repository" . "github.com/restic/restic/test" ) @@ -490,85 +488,3 @@ func TestRestoreNoMetadataOnIgnoredIntermediateDirs(t *testing.T) { "meta data of intermediate directory hasn't been restore") }) } - -func TestMount(t *testing.T) { - - checkSnapshots := func(repo *repository.Repository, mountpoint string, snapshotIDs []backend.ID) { - stSnapshots, err := os.Open(filepath.Join(mountpoint, "snapshots")) - OK(t, err) - namesInSnapshots, err := stSnapshots.Readdirnames(-1) - OK(t, err) - Assert(t, - len(namesInSnapshots) == len(snapshotIDs), - "Invalid number of snapshots: expected %d, got %d", len(snapshotIDs), len(namesInSnapshots)) - - for i, id := range snapshotIDs { - snapshot, err := restic.LoadSnapshot(repo, id) - OK(t, err) - Assert(t, - namesInSnapshots[i] == snapshot.Time.Format(time.RFC3339), - "Invalid snapshot folder name: expected %s, got %s", snapshot.Time.Format(time.RFC3339), namesInSnapshots[i]) - } - OK(t, stSnapshots.Close()) - } - - withTestEnvironment(t, func(env *testEnvironment, global GlobalOptions) { - cmdInit(t, global) - repo, err := global.OpenRepository() - OK(t, err) - - mountpoint, err := ioutil.TempDir(TestTempDir, "restic-test-mount-") - OK(t, err) - - // We remove the mountpoint now to check that cmdMount creates it - OK(t, os.RemoveAll(mountpoint)) - - ready := make(chan struct{}, 1) - go cmdMount(t, global, mountpoint, ready) - <-ready - - stMountPoint, err := os.Open(mountpoint) - OK(t, err) - names, err := stMountPoint.Readdirnames(-1) - OK(t, err) - Assert(t, len(names) == 1 && names[0] == "snapshots", "expected the snapshots directory to exist") - OK(t, stMountPoint.Close()) - - checkSnapshots(repo, mountpoint, []backend.ID{}) - - datafile := filepath.Join("testdata", "backup-data.tar.gz") - fd, err := os.Open(datafile) - if os.IsNotExist(err) { - t.Skipf("unable to find data file %q, skipping", datafile) - return - } - OK(t, err) - OK(t, fd.Close()) - - SetupTarTestFixture(t, env.testdata, datafile) - - // first backup - cmdBackup(t, global, []string{env.testdata}, nil) - snapshotIDs := cmdList(t, global, "snapshots") - Assert(t, len(snapshotIDs) == 1, - "expected one snapshot, got %v", snapshotIDs) - - checkSnapshots(repo, mountpoint, snapshotIDs) - - // second backup, implicit incremental - cmdBackup(t, global, []string{env.testdata}, nil) - snapshotIDs = cmdList(t, global, "snapshots") - Assert(t, len(snapshotIDs) == 2, - "expected two snapshots, got %v", snapshotIDs) - - checkSnapshots(repo, mountpoint, snapshotIDs) - - // third backup, explicit incremental - cmdBackup(t, global, []string{env.testdata}, snapshotIDs[0]) - snapshotIDs = cmdList(t, global, "snapshots") - Assert(t, len(snapshotIDs) == 3, - "expected three snapshots, got %v", snapshotIDs) - - checkSnapshots(repo, mountpoint, snapshotIDs) - }) -} diff --git a/test/backend.go b/test/backend.go index c2d1fe285..8ea7ccdfd 100644 --- a/test/backend.go +++ b/test/backend.go @@ -18,6 +18,7 @@ var ( TestCleanup = getBoolVar("RESTIC_TEST_CLEANUP", true) TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "") RunIntegrationTest = getBoolVar("RESTIC_TEST_INTEGRATION", true) + RunFuseTest = getBoolVar("RESTIC_TEST_FUSE", true) TestSFTPPath = getStringVar("RESTIC_TEST_SFTPPATH", "/usr/lib/ssh:/usr/lib/openssh") TestWalkerPath = getStringVar("RESTIC_TEST_PATH", ".") BenchArchiveDirectory = getStringVar("RESTIC_BENCH_DIR", ".")