forked from TrueCloudLab/restic
ui/progress: add helper to print messages during tests
This commit is contained in:
parent
35277b7797
commit
eda9f7beb4
1 changed files with 35 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
package progress
|
package progress
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
// A Printer can can return a new counter or print messages
|
// A Printer can can return a new counter or print messages
|
||||||
// at different log levels.
|
// at different log levels.
|
||||||
// It must be safe to call its methods from concurrent goroutines.
|
// It must be safe to call its methods from concurrent goroutines.
|
||||||
|
@ -28,3 +30,36 @@ func (*NoopPrinter) P(_ string, _ ...interface{}) {}
|
||||||
func (*NoopPrinter) V(_ string, _ ...interface{}) {}
|
func (*NoopPrinter) V(_ string, _ ...interface{}) {}
|
||||||
|
|
||||||
func (*NoopPrinter) VV(_ string, _ ...interface{}) {}
|
func (*NoopPrinter) VV(_ string, _ ...interface{}) {}
|
||||||
|
|
||||||
|
// TestPrinter prints messages during testing
|
||||||
|
type TestPrinter struct {
|
||||||
|
t testing.TB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewTestPrinter(t testing.TB) *TestPrinter {
|
||||||
|
return &TestPrinter{
|
||||||
|
t: t,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ Printer = (*TestPrinter)(nil)
|
||||||
|
|
||||||
|
func (p *TestPrinter) NewCounter(_ string) *Counter {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *TestPrinter) E(msg string, args ...interface{}) {
|
||||||
|
p.t.Logf("error: "+msg, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *TestPrinter) P(msg string, args ...interface{}) {
|
||||||
|
p.t.Logf("print: "+msg, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *TestPrinter) V(msg string, args ...interface{}) {
|
||||||
|
p.t.Logf("verbose: "+msg, args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *TestPrinter) VV(msg string, args ...interface{}) {
|
||||||
|
p.t.Logf("verbose2: "+msg, args...)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue