mirror of
https://github.com/restic/restic.git
synced 2024-12-22 15:57:07 +00:00
redirect test log output to t.Log()
This commit is contained in:
parent
1f5791222a
commit
841f8bfef0
1 changed files with 16 additions and 2 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -168,6 +169,16 @@ type testEnvironment struct {
|
||||||
gopts GlobalOptions
|
gopts GlobalOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type logOutputter struct {
|
||||||
|
t testing.TB
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *logOutputter) Write(p []byte) (n int, err error) {
|
||||||
|
l.t.Helper()
|
||||||
|
l.t.Log(strings.TrimSuffix(string(p), "\n"))
|
||||||
|
return len(p), nil
|
||||||
|
}
|
||||||
|
|
||||||
// withTestEnvironment creates a test environment and returns a cleanup
|
// withTestEnvironment creates a test environment and returns a cleanup
|
||||||
// function which removes it.
|
// function which removes it.
|
||||||
func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
|
func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
|
||||||
|
@ -200,8 +211,11 @@ func withTestEnvironment(t testing.TB) (env *testEnvironment, cleanup func()) {
|
||||||
Quiet: true,
|
Quiet: true,
|
||||||
CacheDir: env.cache,
|
CacheDir: env.cache,
|
||||||
password: rtest.TestPassword,
|
password: rtest.TestPassword,
|
||||||
stdout: os.Stdout,
|
// stdout and stderr are written to by Warnf etc. That is the written data
|
||||||
stderr: os.Stderr,
|
// usually consists of one or multiple lines and therefore can be handled well
|
||||||
|
// by t.Log.
|
||||||
|
stdout: &logOutputter{t},
|
||||||
|
stderr: &logOutputter{t},
|
||||||
extended: make(options.Options),
|
extended: make(options.Options),
|
||||||
|
|
||||||
// replace this hook with "nil" if listing a filetype more than once is necessary
|
// replace this hook with "nil" if listing a filetype more than once is necessary
|
||||||
|
|
Loading…
Reference in a new issue