mirror of
https://github.com/octoleo/restic.git
synced 2024-11-24 05:37:37 +00:00
a376323331
Previously, they were printed as freeform text. This also adds a ui.Terminal interface to make writing tests easier and also adds a few tests.
28 lines
943 B
Go
28 lines
943 B
Go
package backup
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/restic/restic/internal/errors"
|
|
"github.com/restic/restic/internal/test"
|
|
"github.com/restic/restic/internal/ui"
|
|
)
|
|
|
|
func createJSONProgress() (*ui.MockTerminal, ProgressPrinter) {
|
|
term := &ui.MockTerminal{}
|
|
printer := NewJSONProgress(term, 3)
|
|
return term, printer
|
|
}
|
|
|
|
func TestJSONError(t *testing.T) {
|
|
term, printer := createJSONProgress()
|
|
test.Equals(t, printer.Error("/path", errors.New("error \"message\"")), nil)
|
|
test.Equals(t, []string{"{\"message_type\":\"error\",\"error\":\"error \\\"message\\\"\",\"during\":\"archival\",\"item\":\"/path\"}\n"}, term.Errors)
|
|
}
|
|
|
|
func TestJSONScannerError(t *testing.T) {
|
|
term, printer := createJSONProgress()
|
|
test.Equals(t, printer.ScannerError("/path", errors.New("error \"message\"")), nil)
|
|
test.Equals(t, []string{"{\"message_type\":\"error\",\"error\":\"error \\\"message\\\"\",\"during\":\"scan\",\"item\":\"/path\"}\n"}, term.Errors)
|
|
}
|