2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-30 08:44:02 +00:00
restic/archiver_int_test.go

144 lines
3.0 KiB
Go
Raw Normal View History

2015-03-07 10:53:32 +00:00
package restic
import (
"os"
"testing"
"github.com/restic/restic/pipe"
)
var treeJobs = []string{
"foo/baz/subdir",
2015-03-09 21:56:23 +00:00
"foo/baz",
2015-03-07 10:53:32 +00:00
"foo",
2015-03-09 21:56:23 +00:00
"quu/bar/file1",
"quu/bar/file2",
2015-03-07 10:53:32 +00:00
"quu/foo/file1",
"quu/foo/file2",
"quu/foo/file3",
"quu/foo",
"quu/fooz",
"quu",
"yy/a",
"yy/b",
"yy",
}
var pipeJobs = []string{
"foo/baz/subdir",
"foo/baz/subdir2", // subdir2 added
2015-03-09 21:56:23 +00:00
"foo/baz",
2015-03-07 10:53:32 +00:00
"foo",
2015-03-09 21:56:23 +00:00
"quu/bar/.file1.swp", // file with . added
"quu/bar/file1",
"quu/bar/file2",
2015-03-07 10:53:32 +00:00
"quu/foo/file1", // file2 removed
"quu/foo/file3",
"quu/foo",
"quu",
"quv/file1", // files added and removed
"quv/file2",
"quv",
2015-03-09 21:56:23 +00:00
"yy",
"zz/file1", // files removed and added at the end
2015-03-07 10:53:32 +00:00
"zz/file2",
"zz",
}
var resultJobs = []struct {
path string
2015-03-09 21:56:23 +00:00
action string
2015-03-07 10:53:32 +00:00
}{
2015-03-09 21:56:23 +00:00
{"foo/baz/subdir", "same, not a file"},
{"foo/baz/subdir2", "new, no old job"},
{"foo/baz", "same, not a file"},
{"foo", "same, not a file"},
{"quu/bar/.file1.swp", "new, no old job"},
{"quu/bar/file1", "same, not a file"},
{"quu/bar/file2", "same, not a file"},
{"quu/foo/file1", "same, not a file"},
{"quu/foo/file3", "same, not a file"},
{"quu/foo", "same, not a file"},
{"quu", "same, not a file"},
{"quv/file1", "new, no old job"},
{"quv/file2", "new, no old job"},
{"quv", "new, no old job"},
{"yy", "same, not a file"},
{"zz/file1", "testPipeJob"},
{"zz/file2", "testPipeJob"},
{"zz", "testPipeJob"},
2015-03-07 10:53:32 +00:00
}
type testPipeJob struct {
path string
err error
fi os.FileInfo
res chan<- pipe.Result
}
func (j testPipeJob) Path() string { return j.path }
func (j testPipeJob) Fullpath() string { return j.path }
func (j testPipeJob) Error() error { return j.err }
func (j testPipeJob) Info() os.FileInfo { return j.fi }
func (j testPipeJob) Result() chan<- pipe.Result { return j.res }
func testTreeWalker(done <-chan struct{}, out chan<- WalkTreeJob) {
for _, e := range treeJobs {
select {
case <-done:
return
case out <- WalkTreeJob{Path: e}:
}
}
close(out)
}
func testPipeWalker(done <-chan struct{}, out chan<- pipe.Job) {
for _, e := range pipeJobs {
select {
case <-done:
return
case out <- testPipeJob{path: e}:
}
}
close(out)
}
func TestArchivePipe(t *testing.T) {
done := make(chan struct{})
treeCh := make(chan WalkTreeJob)
pipeCh := make(chan pipe.Job)
go testTreeWalker(done, treeCh)
go testPipeWalker(done, pipeCh)
2015-05-02 13:31:31 +00:00
p := archivePipe{Old: treeCh, New: pipeCh}
2015-03-07 10:53:32 +00:00
ch := make(chan pipe.Job)
go p.compare(done, ch)
i := 0
for job := range ch {
if job.Path() != resultJobs[i].path {
t.Fatalf("wrong job received: wanted %v, got %v", resultJobs[i], job)
}
2015-03-09 21:56:23 +00:00
// switch j := job.(type) {
// case archivePipeJob:
// if j.action != resultJobs[i].action {
// t.Fatalf("wrong action for %v detected: wanted %q, got %q", job.Path(), resultJobs[i].action, j.action)
// }
// case testPipeJob:
// if resultJobs[i].action != "testPipeJob" {
// t.Fatalf("unexpected testPipeJob, expected %q: %v", resultJobs[i].action, j)
// }
// }
2015-03-07 10:53:32 +00:00
i++
}
}