mirror of
https://github.com/restic/restic.git
synced 2026-08-05 05:32:16 +00:00
ui/progress: unexport NoopPrinter and add New* function
This commit is contained in:
@@ -204,7 +204,7 @@ func TestPrepareCheckCache(t *testing.T) {
|
|||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
}
|
}
|
||||||
gopts := global.Options{CacheDir: tmpDirBase}
|
gopts := global.Options{CacheDir: tmpDirBase}
|
||||||
cleanup := prepareCheckCache(testCase.opts, &gopts, &progress.NoopPrinter{})
|
cleanup := prepareCheckCache(testCase.opts, &gopts, progress.NewNoopPrinter())
|
||||||
files, err := os.ReadDir(tmpDirBase)
|
files, err := os.ReadDir(tmpDirBase)
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ func TestPrepareCheckCache(t *testing.T) {
|
|||||||
|
|
||||||
func TestPrepareDefaultCheckCache(t *testing.T) {
|
func TestPrepareDefaultCheckCache(t *testing.T) {
|
||||||
gopts := global.Options{CacheDir: ""}
|
gopts := global.Options{CacheDir: ""}
|
||||||
cleanup := prepareCheckCache(CheckOptions{}, &gopts, &progress.NoopPrinter{})
|
cleanup := prepareCheckCache(CheckOptions{}, &gopts, progress.NewNoopPrinter())
|
||||||
_, err := os.ReadDir(gopts.CacheDir)
|
_, err := os.ReadDir(gopts.CacheDir)
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -57,14 +57,14 @@ func TestInitCopyChunkerParams(t *testing.T) {
|
|||||||
|
|
||||||
var repo *repository.Repository
|
var repo *repository.Repository
|
||||||
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts global.Options) error {
|
err = withTermStatus(t, env.gopts, func(ctx context.Context, gopts global.Options) error {
|
||||||
repo, err = global.OpenRepository(ctx, gopts, &progress.NoopPrinter{})
|
repo, err = global.OpenRepository(ctx, gopts, progress.NewNoopPrinter())
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
var otherRepo *repository.Repository
|
var otherRepo *repository.Repository
|
||||||
err = withTermStatus(t, env2.gopts, func(ctx context.Context, gopts global.Options) error {
|
err = withTermStatus(t, env2.gopts, func(ctx context.Context, gopts global.Options) error {
|
||||||
otherRepo, err = global.OpenRepository(ctx, gopts, &progress.NoopPrinter{})
|
otherRepo, err = global.OpenRepository(ctx, gopts, progress.NewNoopPrinter())
|
||||||
return err
|
return err
|
||||||
})
|
})
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func testRunKeyAddNewKeyUserHost(t testing.TB, gopts global.Options) {
|
|||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
_ = withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error {
|
_ = withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error {
|
||||||
repo, err := global.OpenRepository(ctx, gopts, &progress.NoopPrinter{})
|
repo, err := global.OpenRepository(ctx, gopts, progress.NewNoopPrinter())
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
key, err := repository.SearchKey(ctx, repo, testKeyNewPassword, 2, "")
|
key, err := repository.SearchKey(ctx, repo, testKeyNewPassword, 2, "")
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
@@ -105,7 +105,7 @@ func testRunKeyPasswdUserHost(t testing.TB, newPassword string, gopts global.Opt
|
|||||||
|
|
||||||
gopts.Password = testKeyNewPassword
|
gopts.Password = testKeyNewPassword
|
||||||
_ = withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error {
|
_ = withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error {
|
||||||
repo, err := global.OpenRepository(ctx, gopts, &progress.NoopPrinter{})
|
repo, err := global.OpenRepository(ctx, gopts, progress.NewNoopPrinter())
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
key, err := repository.SearchKey(ctx, repo, testKeyNewPassword, 1, "")
|
key, err := repository.SearchKey(ctx, repo, testKeyNewPassword, 1, "")
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|||||||
@@ -70,10 +70,10 @@ func TestPruneMaxUnusedDuplicate(t *testing.T) {
|
|||||||
usedBlobs.Insert(blob)
|
usedBlobs.Insert(blob)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, &progress.NoopPrinter{})
|
}, progress.NewNoopPrinter())
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
rtest.OK(t, plan.Execute(context.TODO(), &progress.NoopPrinter{}))
|
rtest.OK(t, plan.Execute(context.TODO(), progress.NewNoopPrinter()))
|
||||||
|
|
||||||
rsize := plan.Stats().Size
|
rsize := plan.Stats().Size
|
||||||
remainingUnusedSize := rsize.Duplicate + rsize.Unused - rsize.Remove - rsize.Repackrm
|
remainingUnusedSize := rsize.Duplicate + rsize.Unused - rsize.Remove - rsize.Repackrm
|
||||||
|
|||||||
@@ -41,10 +41,10 @@ func testPrune(t *testing.T, opts repository.PruneOptions, errOnUnused bool) {
|
|||||||
usedBlobs.Insert(blob)
|
usedBlobs.Insert(blob)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, &progress.NoopPrinter{})
|
}, progress.NewNoopPrinter())
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
|
|
||||||
rtest.OK(t, plan.Execute(context.TODO(), &progress.NoopPrinter{}))
|
rtest.OK(t, plan.Execute(context.TODO(), progress.NewNoopPrinter()))
|
||||||
|
|
||||||
repo = repository.TestOpenBackend(t, be)
|
repo = repository.TestOpenBackend(t, be)
|
||||||
repository.TestCheckRepo(t, repo)
|
repository.TestCheckRepo(t, repo)
|
||||||
@@ -165,9 +165,9 @@ func TestPruneSmall(t *testing.T) {
|
|||||||
usedBlobs.Insert(blob)
|
usedBlobs.Insert(blob)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, &progress.NoopPrinter{})
|
}, progress.NewNoopPrinter())
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
rtest.OK(t, plan.Execute(context.TODO(), &progress.NoopPrinter{}))
|
rtest.OK(t, plan.Execute(context.TODO(), progress.NewNoopPrinter()))
|
||||||
|
|
||||||
stats := plan.Stats()
|
stats := plan.Stats()
|
||||||
rtest.Equals(t, stats.Size.Used/blobSize, uint64(numBlobsCreated), fmt.Sprintf("total size of blobs should be %d but is %d",
|
rtest.Equals(t, stats.Size.Used/blobSize, uint64(numBlobsCreated), fmt.Sprintf("total size of blobs should be %d but is %d",
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ func repack(t *testing.T, repo restic.Repository, be backend.Backend, packs rest
|
|||||||
func rebuildAndReloadIndex(t *testing.T, repo *repository.Repository) {
|
func rebuildAndReloadIndex(t *testing.T, repo *repository.Repository) {
|
||||||
rtest.OK(t, repository.RepairIndex(context.TODO(), repo, repository.RepairIndexOptions{
|
rtest.OK(t, repository.RepairIndex(context.TODO(), repo, repository.RepairIndexOptions{
|
||||||
ReadAllPacks: true,
|
ReadAllPacks: true,
|
||||||
}, &progress.NoopPrinter{}))
|
}, progress.NewNoopPrinter()))
|
||||||
|
|
||||||
rtest.OK(t, repo.LoadIndex(context.TODO(), nil))
|
rtest.OK(t, repo.LoadIndex(context.TODO(), nil))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func testRebuildIndex(t *testing.T, readAllPacks bool, damage func(t *testing.T,
|
|||||||
repo = repository.TestOpenBackend(t, be)
|
repo = repository.TestOpenBackend(t, be)
|
||||||
rtest.OK(t, repository.RepairIndex(context.TODO(), repo, repository.RepairIndexOptions{
|
rtest.OK(t, repository.RepairIndex(context.TODO(), repo, repository.RepairIndexOptions{
|
||||||
ReadAllPacks: readAllPacks,
|
ReadAllPacks: readAllPacks,
|
||||||
}, &progress.NoopPrinter{}))
|
}, progress.NewNoopPrinter()))
|
||||||
|
|
||||||
repository.TestCheckRepo(t, repo)
|
repository.TestCheckRepo(t, repo)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ func testRepairBrokenPack(t *testing.T, version uint) {
|
|||||||
buf, err := backendtest.LoadAll(context.TODO(), be, h)
|
buf, err := backendtest.LoadAll(context.TODO(), be, h)
|
||||||
rtest.OK(t, err)
|
rtest.OK(t, err)
|
||||||
rtest.OK(t, be.Remove(context.TODO(), h))
|
rtest.OK(t, be.Remove(context.TODO(), h))
|
||||||
rtest.OK(t, repository.RepairIndex(context.TODO(), repo, repository.RepairIndexOptions{}, &progress.NoopPrinter{}))
|
rtest.OK(t, repository.RepairIndex(context.TODO(), repo, repository.RepairIndexOptions{}, progress.NewNoopPrinter()))
|
||||||
|
|
||||||
rtest.OK(t, be.Save(context.TODO(), h, backend.NewByteReader(buf, be.Hasher())))
|
rtest.OK(t, be.Save(context.TODO(), h, backend.NewByteReader(buf, be.Hasher())))
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ func testRepairBrokenPack(t *testing.T, version uint) {
|
|||||||
|
|
||||||
toRepair, damagedBlobs := test.damage(t, random, repo, be, packsBefore)
|
toRepair, damagedBlobs := test.damage(t, random, repo, be, packsBefore)
|
||||||
|
|
||||||
rtest.OK(t, repository.RepairPacks(context.TODO(), repo, toRepair, &progress.NoopPrinter{}))
|
rtest.OK(t, repository.RepairPacks(context.TODO(), repo, toRepair, progress.NewNoopPrinter()))
|
||||||
// reload index
|
// reload index
|
||||||
rtest.OK(t, repo.LoadIndex(context.TODO(), nil))
|
rtest.OK(t, repo.LoadIndex(context.TODO(), nil))
|
||||||
|
|
||||||
|
|||||||
@@ -989,7 +989,7 @@ func TestRestorerSparseOverwrite(t *testing.T) {
|
|||||||
|
|
||||||
type printerMock struct {
|
type printerMock struct {
|
||||||
s restoreui.State
|
s restoreui.State
|
||||||
progress.NoopPrinter
|
progress.Printer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *printerMock) Update(_ restoreui.State, _ time.Duration) {
|
func (p *printerMock) Update(_ restoreui.State, _ time.Duration) {
|
||||||
@@ -1102,7 +1102,7 @@ func TestRestorerOverwriteBehavior(t *testing.T) {
|
|||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run("", func(t *testing.T) {
|
t.Run("", func(t *testing.T) {
|
||||||
mock := &printerMock{}
|
mock := &printerMock{Printer: progress.NewNoopPrinter()}
|
||||||
progress := restoreui.NewProgress(mock, 0)
|
progress := restoreui.NewProgress(mock, 0)
|
||||||
tempdir := saveSnapshotsAndOverwrite(t, baseSnapshot, overwriteSnapshot, Options{}, Options{Overwrite: test.Overwrite, Progress: progress})
|
tempdir := saveSnapshotsAndOverwrite(t, baseSnapshot, overwriteSnapshot, Options{}, Options{Overwrite: test.Overwrite, Progress: progress})
|
||||||
|
|
||||||
@@ -1154,7 +1154,7 @@ func TestRestorerOverwritePartial(t *testing.T) {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
mock := &printerMock{}
|
mock := &printerMock{Printer: progress.NewNoopPrinter()}
|
||||||
progress := restoreui.NewProgress(mock, 0)
|
progress := restoreui.NewProgress(mock, 0)
|
||||||
saveSnapshotsAndOverwrite(t, baseSnapshot, overwriteSnapshot, Options{}, Options{Overwrite: OverwriteAlways, Progress: progress})
|
saveSnapshotsAndOverwrite(t, baseSnapshot, overwriteSnapshot, Options{}, Options{Overwrite: OverwriteAlways, Progress: progress})
|
||||||
progress.Finish()
|
progress.Finish()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ import (
|
|||||||
|
|
||||||
"github.com/restic/restic/internal/repository"
|
"github.com/restic/restic/internal/repository"
|
||||||
rtest "github.com/restic/restic/internal/test"
|
rtest "github.com/restic/restic/internal/test"
|
||||||
|
"github.com/restic/restic/internal/ui/progress"
|
||||||
restoreui "github.com/restic/restic/internal/ui/restore"
|
restoreui "github.com/restic/restic/internal/ui/restore"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -87,7 +88,7 @@ func testRestorerProgressBar(t *testing.T, dryRun bool) {
|
|||||||
},
|
},
|
||||||
}, noopGetGenericAttributes)
|
}, noopGetGenericAttributes)
|
||||||
|
|
||||||
mock := &printerMock{}
|
mock := &printerMock{Printer: progress.NewNoopPrinter()}
|
||||||
progress := restoreui.NewProgress(mock, 0)
|
progress := restoreui.NewProgress(mock, 0)
|
||||||
res := NewRestorer(repo, sn, Options{Progress: progress, DryRun: dryRun})
|
res := NewRestorer(repo, sn, Options{Progress: progress, DryRun: dryRun})
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
type mockPrinter struct {
|
type mockPrinter struct {
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
progress.NoopPrinter
|
progress.Printer
|
||||||
dirUnchanged, fileNew bool
|
dirUnchanged, fileNew bool
|
||||||
id restic.ID
|
id restic.ID
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ func (p *mockPrinter) Reset() {}
|
|||||||
func TestProgress(t *testing.T) {
|
func TestProgress(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
prnt := &mockPrinter{}
|
prnt := &mockPrinter{Printer: progress.NewNoopPrinter()}
|
||||||
prog := NewProgress(prnt, time.Millisecond)
|
prog := NewProgress(prnt, time.Millisecond)
|
||||||
|
|
||||||
prog.StartFile("foo")
|
prog.StartFile("foo")
|
||||||
|
|||||||
@@ -32,27 +32,32 @@ type Printer interface {
|
|||||||
VV(msg string, args ...interface{})
|
VV(msg string, args ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoopPrinter discards all messages
|
// noopPrinter discards all messages.
|
||||||
type NoopPrinter struct{}
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (*NoopPrinter) NewCounterTerminalOnly(_ string) *Counter {
|
func (*noopPrinter) NewCounterTerminalOnly(_ string) *Counter {
|
||||||
return nil
|
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{}) {}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ type mockPrinter struct {
|
|||||||
trace printerTrace
|
trace printerTrace
|
||||||
items itemTrace
|
items itemTrace
|
||||||
errors errorTrace
|
errors errorTrace
|
||||||
progress.NoopPrinter
|
progress.Printer
|
||||||
}
|
}
|
||||||
|
|
||||||
const mockFinishDuration = 42 * time.Second
|
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) {
|
func testProgress(fn func(progress *Progress) bool) (printerTrace, itemTrace, errorTrace) {
|
||||||
printer := &mockPrinter{}
|
printer := &mockPrinter{Printer: progress.NewNoopPrinter()}
|
||||||
progress := NewProgress(printer, 0)
|
progress := NewProgress(printer, 0)
|
||||||
final := fn(progress)
|
final := fn(progress)
|
||||||
progress.update(0, final)
|
progress.update(0, final)
|
||||||
|
|||||||
Reference in New Issue
Block a user