2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-16 01:57:10 +00:00

backend: Add test for listing files with layouts

This commit is contained in:
Alexander Neumann 2017-04-10 23:21:04 +02:00
parent 36b1c0898c
commit e2af5890f3
2 changed files with 88 additions and 6 deletions

View File

@ -2,6 +2,7 @@ package local
import ( import (
"path/filepath" "path/filepath"
"restic"
. "restic/test" . "restic/test"
"testing" "testing"
) )
@ -14,10 +15,23 @@ func TestLayout(t *testing.T) {
filename string filename string
layout string layout string
failureExpected bool failureExpected bool
datafiles map[string]bool
}{ }{
{"repo-layout-local.tar.gz", "", false}, {"repo-layout-local.tar.gz", "", false, map[string]bool{
{"repo-layout-cloud.tar.gz", "", false}, "aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false,
{"repo-layout-s3-old.tar.gz", "", false}, "fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false,
"c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false,
}},
{"repo-layout-cloud.tar.gz", "", false, map[string]bool{
"fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false,
"c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false,
"aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false,
}},
{"repo-layout-s3-old.tar.gz", "", false, map[string]bool{
"fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false,
"c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false,
"aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false,
}},
} }
for _, test := range tests { for _, test := range tests {
@ -37,6 +51,33 @@ func TestLayout(t *testing.T) {
t.Fatalf("Open() returned nil but no error") t.Fatalf("Open() returned nil but no error")
} }
datafiles := make(map[string]bool)
for id := range be.List(restic.DataFile, nil) {
datafiles[id] = false
}
if len(datafiles) == 0 {
t.Errorf("List() returned zero data files")
}
for id := range test.datafiles {
if _, ok := datafiles[id]; !ok {
t.Errorf("datafile with id %v not found", id)
}
datafiles[id] = true
}
for id, v := range datafiles {
if !v {
t.Errorf("unexpected id %v found", id)
}
}
if err = be.Close(); err != nil {
t.Errorf("Close() returned error %v", err)
}
RemoveAll(t, filepath.Join(path, "repo")) RemoveAll(t, filepath.Join(path, "repo"))
}) })
} }

View File

@ -3,6 +3,7 @@ package sftp_test
import ( import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"restic"
"restic/backend/sftp" "restic/backend/sftp"
. "restic/test" . "restic/test"
"testing" "testing"
@ -20,10 +21,23 @@ func TestLayout(t *testing.T) {
filename string filename string
layout string layout string
failureExpected bool failureExpected bool
datafiles map[string]bool
}{ }{
{"repo-layout-local.tar.gz", "", false}, {"repo-layout-local.tar.gz", "", false, map[string]bool{
{"repo-layout-cloud.tar.gz", "", false}, "aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false,
{"repo-layout-s3-old.tar.gz", "", false}, "fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false,
"c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false,
}},
{"repo-layout-cloud.tar.gz", "", false, map[string]bool{
"fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false,
"c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false,
"aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false,
}},
{"repo-layout-s3-old.tar.gz", "", false, map[string]bool{
"fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false,
"c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false,
"aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false,
}},
} }
for _, test := range tests { for _, test := range tests {
@ -44,6 +58,33 @@ func TestLayout(t *testing.T) {
t.Fatalf("Open() returned nil but no error") t.Fatalf("Open() returned nil but no error")
} }
datafiles := make(map[string]bool)
for id := range be.List(restic.DataFile, nil) {
datafiles[id] = false
}
if len(datafiles) == 0 {
t.Errorf("List() returned zero data files")
}
for id := range test.datafiles {
if _, ok := datafiles[id]; !ok {
t.Errorf("datafile with id %v not found", id)
}
datafiles[id] = true
}
for id, v := range datafiles {
if !v {
t.Errorf("unexpected id %v found", id)
}
}
if err = be.Close(); err != nil {
t.Errorf("Close() returned error %v", err)
}
RemoveAll(t, filepath.Join(path, "repo")) RemoveAll(t, filepath.Join(path, "repo"))
}) })
} }