ui: restore --delete indicates number of deleted files (#5100)

* ui: restore --delete indicates number of deleted files

* adds new field `FilesDeleted` to the State struct, JSON and text progress updaters
* increment FilesDeleted count when ReportedDeletedFile

* ui: collect the files to be deleted, delete, then update the count post deletion

* docs: update scripting output fields for restore command

ui: report deleted directories and refactor function name to ReportDeletion
This commit is contained in:
Srigovind Nayak
2024-12-01 19:59:11 +05:30
committed by GitHub
parent 2f0049cd6c
commit d7d9af4c9f
9 changed files with 64 additions and 21 deletions

View File

@@ -17,31 +17,31 @@ func createTextProgress() (*ui.MockTerminal, ProgressPrinter) {
func TestPrintUpdate(t *testing.T) {
term, printer := createTextProgress()
printer.Update(State{3, 11, 0, 29, 47, 0}, 5*time.Second)
printer.Update(State{3, 11, 0, 0, 29, 47, 0}, 5*time.Second)
test.Equals(t, []string{"[0:05] 61.70% 3 files/dirs 29 B, total 11 files/dirs 47 B"}, term.Output)
}
func TestPrintUpdateWithSkipped(t *testing.T) {
term, printer := createTextProgress()
printer.Update(State{3, 11, 2, 29, 47, 59}, 5*time.Second)
printer.Update(State{3, 11, 2, 0, 29, 47, 59}, 5*time.Second)
test.Equals(t, []string{"[0:05] 61.70% 3 files/dirs 29 B, total 11 files/dirs 47 B, skipped 2 files/dirs 59 B"}, term.Output)
}
func TestPrintSummaryOnSuccess(t *testing.T) {
term, printer := createTextProgress()
printer.Finish(State{11, 11, 0, 47, 47, 0}, 5*time.Second)
printer.Finish(State{11, 11, 0, 0, 47, 47, 0}, 5*time.Second)
test.Equals(t, []string{"Summary: Restored 11 files/dirs (47 B) in 0:05"}, term.Output)
}
func TestPrintSummaryOnErrors(t *testing.T) {
term, printer := createTextProgress()
printer.Finish(State{3, 11, 0, 29, 47, 0}, 5*time.Second)
printer.Finish(State{3, 11, 0, 0, 29, 47, 0}, 5*time.Second)
test.Equals(t, []string{"Summary: Restored 3 / 11 files/dirs (29 B / 47 B) in 0:05"}, term.Output)
}
func TestPrintSummaryOnSuccessWithSkipped(t *testing.T) {
term, printer := createTextProgress()
printer.Finish(State{11, 11, 2, 47, 47, 59}, 5*time.Second)
printer.Finish(State{11, 11, 2, 0, 47, 47, 59}, 5*time.Second)
test.Equals(t, []string{"Summary: Restored 11 files/dirs (47 B) in 0:05, skipped 2 files/dirs 59 B"}, term.Output)
}