ui/progress: unexport NoopPrinter and add New* function

This commit is contained in:
Michael Eischer
2026-06-05 14:48:44 +02:00
parent e8ed2434cd
commit 0bbfb072af
13 changed files with 41 additions and 35 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ import (
type mockPrinter struct {
sync.Mutex
progress.NoopPrinter
progress.Printer
dirUnchanged, fileNew bool
id restic.ID
}
@@ -48,7 +48,7 @@ func (p *mockPrinter) Reset() {}
func TestProgress(t *testing.T) {
t.Parallel()
prnt := &mockPrinter{}
prnt := &mockPrinter{Printer: progress.NewNoopPrinter()}
prog := NewProgress(prnt, time.Millisecond)
prog.StartFile("foo")
+16 -11
View File
@@ -32,27 +32,32 @@ type Printer interface {
VV(msg string, args ...interface{})
}
// NoopPrinter discards all messages
type NoopPrinter struct{}
// noopPrinter discards all messages.
type noopPrinter struct{}
var _ Printer = (*NoopPrinter)(nil)
var _ Printer = (*noopPrinter)(nil)
func (*NoopPrinter) NewCounter(_ string) *Counter {
// NewNoopPrinter returns a Printer that discards all messages.
func NewNoopPrinter() Printer {
return &noopPrinter{}
}
func (*noopPrinter) NewCounter(_ string) *Counter {
return nil
}
func (*NoopPrinter) NewCounterTerminalOnly(_ string) *Counter {
func (*noopPrinter) NewCounterTerminalOnly(_ string) *Counter {
return nil
}
func (*NoopPrinter) E(_ string, _ ...interface{}) {}
func (*noopPrinter) E(_ string, _ ...interface{}) {}
func (*NoopPrinter) S(_ string, _ ...interface{}) {}
func (*noopPrinter) S(_ string, _ ...interface{}) {}
func (*NoopPrinter) PT(_ string, _ ...interface{}) {}
func (*noopPrinter) PT(_ string, _ ...interface{}) {}
func (*NoopPrinter) P(_ string, _ ...interface{}) {}
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{}) {}
+2 -2
View File
@@ -37,7 +37,7 @@ type mockPrinter struct {
trace printerTrace
items itemTrace
errors errorTrace
progress.NoopPrinter
progress.Printer
}
const mockFinishDuration = 42 * time.Second
@@ -57,7 +57,7 @@ func (p *mockPrinter) Finish(progress State, _ time.Duration) {
}
func testProgress(fn func(progress *Progress) bool) (printerTrace, itemTrace, errorTrace) {
printer := &mockPrinter{}
printer := &mockPrinter{Printer: progress.NewNoopPrinter()}
progress := NewProgress(printer, 0)
final := fn(progress)
progress.update(0, final)