mirror of
https://github.com/octoleo/restic.git
synced 2024-11-30 00:33:57 +00:00
commit
30ff7413be
@ -159,6 +159,15 @@ func testRunFind(t testing.TB, gopts GlobalOptions, pattern string) []string {
|
|||||||
return strings.Split(string(buf.Bytes()), "\n")
|
return strings.Split(string(buf.Bytes()), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testRunForget(t testing.TB, gopts GlobalOptions, args ...string) {
|
||||||
|
opts := ForgetOptions{}
|
||||||
|
OK(t, runForget(opts, gopts, args))
|
||||||
|
}
|
||||||
|
|
||||||
|
func testRunPrune(t testing.TB, gopts GlobalOptions) {
|
||||||
|
OK(t, runPrune(gopts))
|
||||||
|
}
|
||||||
|
|
||||||
func TestBackup(t *testing.T) {
|
func TestBackup(t *testing.T) {
|
||||||
withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) {
|
withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) {
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
||||||
@ -947,3 +956,33 @@ func TestCheckRestoreNoLock(t *testing.T) {
|
|||||||
testRunRestore(t, gopts, filepath.Join(env.base, "restore"), snapshotIDs[0])
|
testRunRestore(t, gopts, filepath.Join(env.base, "restore"), snapshotIDs[0])
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrune(t *testing.T) {
|
||||||
|
withTestEnvironment(t, func(env *testEnvironment, gopts GlobalOptions) {
|
||||||
|
datafile := filepath.Join("testdata", "backup-data.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{}
|
||||||
|
|
||||||
|
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "1")}, opts, gopts)
|
||||||
|
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "2")}, opts, gopts)
|
||||||
|
testRunBackup(t, []string{filepath.Join(env.testdata, "0", "0", "3")}, opts, gopts)
|
||||||
|
|
||||||
|
snapshotIDs := testRunList(t, "snapshots", gopts)
|
||||||
|
Assert(t, len(snapshotIDs) == 3,
|
||||||
|
"expected one snapshot, got %v", snapshotIDs)
|
||||||
|
|
||||||
|
testRunForget(t, gopts, snapshotIDs[0].String())
|
||||||
|
testRunPrune(t, gopts)
|
||||||
|
testRunCheck(t, gopts)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
@ -169,7 +169,7 @@ func (idx *Index) AddPack(id restic.ID, size int64, entries []restic.Blob) error
|
|||||||
return errors.Errorf("pack %v already present in the index", id.Str())
|
return errors.Errorf("pack %v already present in the index", id.Str())
|
||||||
}
|
}
|
||||||
|
|
||||||
idx.Packs[id] = Pack{Size: size, Entries: entries}
|
idx.Packs[id] = Pack{ID: id, Size: size, Entries: entries}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,14 @@ func createFilledRepo(t testing.TB, snapshots int, dup float32) (restic.Reposito
|
|||||||
|
|
||||||
func validateIndex(t testing.TB, repo restic.Repository, idx *Index) {
|
func validateIndex(t testing.TB, repo restic.Repository, idx *Index) {
|
||||||
for id := range repo.List(restic.DataFile, nil) {
|
for id := range repo.List(restic.DataFile, nil) {
|
||||||
if _, ok := idx.Packs[id]; !ok {
|
p, ok := idx.Packs[id]
|
||||||
|
if !ok {
|
||||||
t.Errorf("pack %v missing from index", id.Str())
|
t.Errorf("pack %v missing from index", id.Str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !p.ID.Equal(id) {
|
||||||
|
t.Errorf("pack %v has invalid ID: want %v, got %v", id.Str(), id, p.ID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +155,7 @@ func BenchmarkIndexSave(b *testing.B) {
|
|||||||
|
|
||||||
for i := 0; i < 8000; i++ {
|
for i := 0; i < 8000; i++ {
|
||||||
entries := make([]restic.Blob, 0, 200)
|
entries := make([]restic.Blob, 0, 200)
|
||||||
for j := 0; j < len(entries); j++ {
|
for j := 0; j < cap(entries); j++ {
|
||||||
entries = append(entries, restic.Blob{
|
entries = append(entries, restic.Blob{
|
||||||
ID: restic.NewRandomID(),
|
ID: restic.NewRandomID(),
|
||||||
Length: 1000,
|
Length: 1000,
|
||||||
|
Loading…
Reference in New Issue
Block a user