mirror of
https://github.com/restic/restic.git
synced 2026-08-25 23:13:18 +00:00
Use package "restic/test"
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
package pipe_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// assert fails the test if the condition is false.
|
||||
func assert(tb testing.TB, condition bool, msg string, v ...interface{}) {
|
||||
if !condition {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
fmt.Printf("\033[31m%s:%d: "+msg+"\033[39m\n\n", append([]interface{}{filepath.Base(file), line}, v...)...)
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
// ok fails the test if an err is not nil.
|
||||
func ok(tb testing.TB, err error) {
|
||||
if err != nil {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
fmt.Printf("\033[31m%s:%d: unexpected error: %s\033[39m\n\n", filepath.Base(file), line, err.Error())
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
|
||||
// equals fails the test if exp is not equal to act.
|
||||
func equals(tb testing.TB, exp, act interface{}) {
|
||||
if !reflect.DeepEqual(exp, act) {
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
fmt.Printf("\033[31m%s:%d:\n\n\texp: %#v\n\n\tgot: %#v\033[39m\n\n", filepath.Base(file), line, exp, act)
|
||||
tb.FailNow()
|
||||
}
|
||||
}
|
||||
+13
-12
@@ -9,6 +9,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/pipe"
|
||||
. "github.com/restic/restic/test"
|
||||
)
|
||||
|
||||
var testWalkerPath = flag.String("test.walkerpath", ".", "pipeline walker testpath (default: .)")
|
||||
@@ -49,7 +50,7 @@ func TestPipelineWalkerWithSplit(t *testing.T) {
|
||||
}
|
||||
|
||||
before, err := statPath(*testWalkerPath)
|
||||
ok(t, err)
|
||||
OK(t, err)
|
||||
|
||||
t.Logf("walking path %s with %d dirs, %d files", *testWalkerPath,
|
||||
before.dirs, before.files)
|
||||
@@ -120,7 +121,7 @@ func TestPipelineWalkerWithSplit(t *testing.T) {
|
||||
|
||||
resCh := make(chan pipe.Result, 1)
|
||||
err = pipe.Walk([]string{*testWalkerPath}, done, jobs, resCh)
|
||||
ok(t, err)
|
||||
OK(t, err)
|
||||
|
||||
// wait for all workers to terminate
|
||||
wg.Wait()
|
||||
@@ -131,7 +132,7 @@ func TestPipelineWalkerWithSplit(t *testing.T) {
|
||||
t.Logf("walked path %s with %d dirs, %d files", *testWalkerPath,
|
||||
after.dirs, after.files)
|
||||
|
||||
assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
Assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
}
|
||||
|
||||
func TestPipelineWalker(t *testing.T) {
|
||||
@@ -140,7 +141,7 @@ func TestPipelineWalker(t *testing.T) {
|
||||
}
|
||||
|
||||
before, err := statPath(*testWalkerPath)
|
||||
ok(t, err)
|
||||
OK(t, err)
|
||||
|
||||
t.Logf("walking path %s with %d dirs, %d files", *testWalkerPath,
|
||||
before.dirs, before.files)
|
||||
@@ -160,7 +161,7 @@ func TestPipelineWalker(t *testing.T) {
|
||||
// channel is closed
|
||||
return
|
||||
}
|
||||
assert(t, job != nil, "job is nil")
|
||||
Assert(t, job != nil, "job is nil")
|
||||
|
||||
switch j := job.(type) {
|
||||
case pipe.Dir:
|
||||
@@ -200,7 +201,7 @@ func TestPipelineWalker(t *testing.T) {
|
||||
|
||||
resCh := make(chan pipe.Result, 1)
|
||||
err = pipe.Walk([]string{*testWalkerPath}, done, jobs, resCh)
|
||||
ok(t, err)
|
||||
OK(t, err)
|
||||
|
||||
// wait for all workers to terminate
|
||||
wg.Wait()
|
||||
@@ -211,7 +212,7 @@ func TestPipelineWalker(t *testing.T) {
|
||||
t.Logf("walked path %s with %d dirs, %d files", *testWalkerPath,
|
||||
after.dirs, after.files)
|
||||
|
||||
assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
Assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
}
|
||||
|
||||
func BenchmarkPipelineWalker(b *testing.B) {
|
||||
@@ -300,7 +301,7 @@ func BenchmarkPipelineWalker(b *testing.B) {
|
||||
|
||||
resCh := make(chan pipe.Result, 1)
|
||||
err := pipe.Walk([]string{*testWalkerPath}, done, jobs, resCh)
|
||||
ok(b, err)
|
||||
OK(b, err)
|
||||
|
||||
// wait for all workers to terminate
|
||||
wg.Wait()
|
||||
@@ -320,7 +321,7 @@ func TestPipelineWalkerMultiple(t *testing.T) {
|
||||
paths, err := filepath.Glob(filepath.Join(*testWalkerPath, "*"))
|
||||
|
||||
before, err := statPath(*testWalkerPath)
|
||||
ok(t, err)
|
||||
OK(t, err)
|
||||
|
||||
t.Logf("walking paths %v with %d dirs, %d files", paths,
|
||||
before.dirs, before.files)
|
||||
@@ -337,7 +338,7 @@ func TestPipelineWalkerMultiple(t *testing.T) {
|
||||
// channel is closed
|
||||
return
|
||||
}
|
||||
assert(t, job != nil, "job is nil")
|
||||
Assert(t, job != nil, "job is nil")
|
||||
|
||||
switch j := job.(type) {
|
||||
case pipe.Dir:
|
||||
@@ -377,7 +378,7 @@ func TestPipelineWalkerMultiple(t *testing.T) {
|
||||
|
||||
resCh := make(chan pipe.Result, 1)
|
||||
err = pipe.Walk(paths, done, jobs, resCh)
|
||||
ok(t, err)
|
||||
OK(t, err)
|
||||
|
||||
// wait for all workers to terminate
|
||||
wg.Wait()
|
||||
@@ -387,5 +388,5 @@ func TestPipelineWalkerMultiple(t *testing.T) {
|
||||
|
||||
t.Logf("walked %d paths with %d dirs, %d files", len(paths), after.dirs, after.files)
|
||||
|
||||
assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
Assert(t, before == after, "stats do not match, expected %v, got %v", before, after)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user