2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-22 10:58:55 +00:00

restore: More descriptive field names for the JSON output

This commit is contained in:
Michael Eischer 2023-06-09 12:01:53 +02:00
parent b2b0760eb0
commit 07d1f8047e
2 changed files with 11 additions and 11 deletions

View File

@ -25,9 +25,9 @@ func (t *jsonPrinter) Update(filesFinished, filesTotal, allBytesWritten, allByte
MessageType: "status",
SecondsElapsed: uint64(duration / time.Second),
TotalFiles: filesTotal,
FilesDone: filesFinished,
FilesRestored: filesFinished,
TotalBytes: allBytesTotal,
BytesDone: allBytesWritten,
BytesRestored: allBytesWritten,
}
if allBytesTotal > 0 {
@ -42,9 +42,9 @@ func (t *jsonPrinter) Finish(filesFinished, filesTotal, allBytesWritten, allByte
MessageType: "summary",
SecondsElapsed: uint64(duration / time.Second),
TotalFiles: filesTotal,
FilesDone: filesFinished,
FilesRestored: filesFinished,
TotalBytes: allBytesTotal,
BytesDone: allBytesWritten,
BytesRestored: allBytesWritten,
}
t.print(status)
}
@ -54,16 +54,16 @@ type statusUpdate struct {
SecondsElapsed uint64 `json:"seconds_elapsed,omitempty"`
PercentDone float64 `json:"percent_done"`
TotalFiles uint64 `json:"total_files,omitempty"`
FilesDone uint64 `json:"files_done,omitempty"`
FilesRestored uint64 `json:"files_restored,omitempty"`
TotalBytes uint64 `json:"total_bytes,omitempty"`
BytesDone uint64 `json:"bytes_done,omitempty"`
BytesRestored uint64 `json:"bytes_restored,omitempty"`
}
type summaryOutput struct {
MessageType string `json:"message_type"` // "summary"
SecondsElapsed uint64 `json:"seconds_elapsed,omitempty"`
TotalFiles uint64 `json:"total_files,omitempty"`
FilesDone uint64 `json:"files_done,omitempty"`
FilesRestored uint64 `json:"files_restored,omitempty"`
TotalBytes uint64 `json:"total_bytes,omitempty"`
BytesDone uint64 `json:"bytes_done,omitempty"`
BytesRestored uint64 `json:"bytes_restored,omitempty"`
}

View File

@ -11,19 +11,19 @@ func TestJSONPrintUpdate(t *testing.T) {
term := &mockTerm{}
printer := NewJSONProgress(term)
printer.Update(3, 11, 29, 47, 5*time.Second)
test.Equals(t, []string{"{\"message_type\":\"status\",\"seconds_elapsed\":5,\"percent_done\":0.6170212765957447,\"total_files\":11,\"files_done\":3,\"total_bytes\":47,\"bytes_done\":29}\n"}, term.output)
test.Equals(t, []string{"{\"message_type\":\"status\",\"seconds_elapsed\":5,\"percent_done\":0.6170212765957447,\"total_files\":11,\"files_restored\":3,\"total_bytes\":47,\"bytes_restored\":29}\n"}, term.output)
}
func TestJSONPrintSummaryOnSuccess(t *testing.T) {
term := &mockTerm{}
printer := NewJSONProgress(term)
printer.Finish(11, 11, 47, 47, 5*time.Second)
test.Equals(t, []string{"{\"message_type\":\"summary\",\"seconds_elapsed\":5,\"total_files\":11,\"files_done\":11,\"total_bytes\":47,\"bytes_done\":47}\n"}, term.output)
test.Equals(t, []string{"{\"message_type\":\"summary\",\"seconds_elapsed\":5,\"total_files\":11,\"files_restored\":11,\"total_bytes\":47,\"bytes_restored\":47}\n"}, term.output)
}
func TestJSONPrintSummaryOnErrors(t *testing.T) {
term := &mockTerm{}
printer := NewJSONProgress(term)
printer.Finish(3, 11, 29, 47, 5*time.Second)
test.Equals(t, []string{"{\"message_type\":\"summary\",\"seconds_elapsed\":5,\"total_files\":11,\"files_done\":3,\"total_bytes\":47,\"bytes_done\":29}\n"}, term.output)
test.Equals(t, []string{"{\"message_type\":\"summary\",\"seconds_elapsed\":5,\"total_files\":11,\"files_restored\":3,\"total_bytes\":47,\"bytes_restored\":29}\n"}, term.output)
}