From 2a568e624dbe04be137d73d09af7709367145e08 Mon Sep 17 00:00:00 2001 From: jgfrm Date: Mon, 6 Feb 2017 16:03:46 +0100 Subject: [PATCH] integration test added --- src/cmds/restic/integration_helpers_test.go | 9 ++++- src/cmds/restic/integration_test.go | 39 ++++++++++++++++++++ src/cmds/restic/testdata/test.hl.tar.gz | Bin 0 -> 211 bytes src/restic/node.go | 1 - 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/cmds/restic/testdata/test.hl.tar.gz diff --git a/src/cmds/restic/integration_helpers_test.go b/src/cmds/restic/integration_helpers_test.go index 72fb09f44..9e162a7f2 100644 --- a/src/cmds/restic/integration_helpers_test.go +++ b/src/cmds/restic/integration_helpers_test.go @@ -15,6 +15,7 @@ import ( type dirEntry struct { path string fi os.FileInfo + link uint64 } func walkDir(dir string) <-chan *dirEntry { @@ -32,10 +33,16 @@ func walkDir(dir string) <-chan *dirEntry { fmt.Fprintf(os.Stderr, "error: %v\n", err) return nil } - + + stat, err := toStatT(info.Sys()) + if !err { + return nil + } + ch <- &dirEntry{ path: name, fi: info, + link: stat.nlink(), } return nil diff --git a/src/cmds/restic/integration_test.go b/src/cmds/restic/integration_test.go index 426367724..365a00773 100644 --- a/src/cmds/restic/integration_test.go +++ b/src/cmds/restic/integration_test.go @@ -1011,3 +1011,42 @@ func TestPrune(t *testing.T) { testRunCheck(t, gopts) }) } + +func TestHardLink(t *testing.T) { + withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) { + datafile := filepath.Join("testdata", "test.hl.tar.gz") + fd, err := os.Open(datafile) + if os.IsNotExist(errors.Cause(err)) { + t.Skipf("unable to find data file %q, skipping", datafile) + return + } + OK(t, err) + OK(t, fd.Close()) + + testRunInit(t, gopts) + + SetupTarTestFixture(t, env.testdata, datafile) + opts := BackupOptions{} + + // first backup + testRunBackup(t, []string{env.testdata}, opts, gopts) + snapshotIDs := testRunList(t, "snapshots", gopts) + Assert(t, len(snapshotIDs) == 1, + "expected one snapshot, got %v", snapshotIDs) + + testRunCheck(t, gopts) + stat1 := dirStats(env.repo) + + // restore all backups and compare + for i, snapshotID := range snapshotIDs { + restoredir := filepath.Join(env.base, fmt.Sprintf("restore%d", i)) + t.Logf("restoring snapshot %v to %v", snapshotID.Str(), restoredir) + testRunRestore(t, gopts, restoredir, snapshotIDs[0]) + Assert(t, directoriesEqualContents(env.testdata, filepath.Join(restoredir, "testdata")), + "directories are not equal") + } + + testRunCheck(t, gopts) + }) +} + diff --git a/src/cmds/restic/testdata/test.hl.tar.gz b/src/cmds/restic/testdata/test.hl.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..33e580939971a3be4512e542cdc8ef9167eac66a GIT binary patch literal 211 zcmb2|=HL+No)N*oT#{N`qL-1QSCUx7@b*$P*C7J|hl@I@(gNxyRbu^*H03W{`P*Fd zsJtL+w7~nH84Gw)9=JVAD+w|+ymp!W>&khzI!=B4-&^QtV%e!xdd_lv@5aJES9>g{ z+m&CN<$G>pBi%iwY>A&^}YqiPHh*jZ2Q;$uRG?J;kzGO_OBN{7-4?&@t@EC7!csW_gDtU LL