2024-07-27 23:06:26 +00:00
|
|
|
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)
|
2024-08-03 19:29:10 +00:00
|
|
|
test.Equals(t, []string{"{\"message_type\":\"error\",\"error\":{\"message\":\"error \\\"message\\\"\"},\"during\":\"archival\",\"item\":\"/path\"}\n"}, term.Errors)
|
2024-07-27 23:06:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestJSONScannerError(t *testing.T) {
|
|
|
|
term, printer := createJSONProgress()
|
|
|
|
test.Equals(t, printer.ScannerError("/path", errors.New("error \"message\"")), nil)
|
2024-08-03 19:29:10 +00:00
|
|
|
test.Equals(t, []string{"{\"message_type\":\"error\",\"error\":{\"message\":\"error \\\"message\\\"\"},\"during\":\"scan\",\"item\":\"/path\"}\n"}, term.Errors)
|
2024-07-27 23:06:26 +00:00
|
|
|
}
|