1
0
mirror of https://github.com/restic/restic.git synced 2025-08-17 09:27:25 +00:00
Files
.github
changelog
cmd
contrib
doc
docker
helpers
internal
archiver
backend
bloblru
checker
crypto
debug
dump
errors
feature
filter
fs
fuse
migrations
options
repository
restic
restorer
selfupdate
test
textfile
ui
backup
json.go
json_test.go
progress.go
progress_test.go
rate_estimator.go
rate_estimator_test.go
text.go
text_test.go
progress
restore
signals
table
termstatus
format.go
format_test.go
message.go
mock.go
terminal.go
walker
.gitattributes
.gitignore
.golangci.yml
.readthedocs.yaml
CHANGELOG.md
CONTRIBUTING.md
GOVERNANCE.md
LICENSE
Makefile
README.md
VERSION
build.go
doc.go
go.mod
go.sum
restic/internal/ui/backup/progress_test.go

78 lines
1.7 KiB
Go

package backup
import (
"sync"
"testing"
"time"
"github.com/restic/restic/internal/archiver"
"github.com/restic/restic/internal/restic"
)
type mockPrinter struct {
sync.Mutex
dirUnchanged, fileNew bool
id restic.ID
}
func (p *mockPrinter) Update(_, _ Counter, _ uint, _ map[string]struct{}, _ time.Time, _ uint64) {
}
func (p *mockPrinter) Error(_ string, err error) error { return err }
func (p *mockPrinter) ScannerError(_ string, err error) error { return err }
func (p *mockPrinter) CompleteItem(messageType string, _ string, _ archiver.ItemStats, _ time.Duration) {
p.Lock()
defer p.Unlock()
switch messageType {
case "dir unchanged":
p.dirUnchanged = true
case "file new":
p.fileNew = true
}
}
func (p *mockPrinter) ReportTotal(_ time.Time, _ archiver.ScanStats) {}
func (p *mockPrinter) Finish(id restic.ID, _ time.Time, _ *archiver.Summary, _ bool) {
p.Lock()
defer p.Unlock()
p.id = id
}
func (p *mockPrinter) Reset() {}
func (p *mockPrinter) P(_ string, _ ...interface{}) {}
func (p *mockPrinter) V(_ string, _ ...interface{}) {}
func TestProgress(t *testing.T) {
t.Parallel()
prnt := &mockPrinter{}
prog := NewProgress(prnt, time.Millisecond)
prog.StartFile("foo")
prog.CompleteBlob(1024)
// "dir unchanged"
node := restic.Node{Type: "dir"}
prog.CompleteItem("foo", &node, &node, archiver.ItemStats{}, 0)
// "file new"
node.Type = "file"
prog.CompleteItem("foo", nil, &node, archiver.ItemStats{}, 0)
time.Sleep(10 * time.Millisecond)
id := restic.NewRandomID()
prog.Finish(id, nil, false)
if !prnt.dirUnchanged {
t.Error(`"dir unchanged" event not seen`)
}
if !prnt.fileNew {
t.Error(`"file new" event not seen`)
}
if prnt.id != id {
t.Errorf("id not stored (has %v)", prnt.id)
}
}