57624629d6
Before this change, integration tests often could not be run on backends with differing features from the local system that goldenized them. In particular, differences in modtime precision, checksum support, and encoding would cause false positives. After this change, the tests more accurately account for the features of the backend being tested, which allows us to see true positives more clearly, and more meaningfully assess whether a backend is supported.
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package bisync
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"github.com/rclone/rclone/fs"
|
|
"github.com/rclone/rclone/lib/encoder"
|
|
"github.com/rclone/rclone/lib/terminal"
|
|
)
|
|
|
|
func (b *bisyncRun) indentf(tag, file, format string, args ...interface{}) {
|
|
b.indent(tag, file, fmt.Sprintf(format, args...))
|
|
}
|
|
|
|
func (b *bisyncRun) indent(tag, file, msg string) {
|
|
logf := fs.Infof
|
|
switch {
|
|
case tag == "ERROR":
|
|
tag = ""
|
|
logf = fs.Errorf
|
|
case tag == "INFO":
|
|
tag = ""
|
|
case strings.HasPrefix(tag, "!"):
|
|
tag = tag[1:]
|
|
logf = fs.Logf
|
|
}
|
|
|
|
tag = Color(terminal.BlueFg, tag)
|
|
msg = Color(terminal.MagentaFg, msg)
|
|
file = Color(terminal.CyanFg, escapePath(file, false))
|
|
logf(nil, "- %-18s%-43s - %s", tag, msg, file)
|
|
}
|
|
|
|
// escapePath will escape control characters in path.
|
|
// It won't quote just due to backslashes on Windows.
|
|
func escapePath(path string, forceQuotes bool) string {
|
|
path = encode(path)
|
|
test := path
|
|
if runtime.GOOS == "windows" {
|
|
test = strings.ReplaceAll(path, "\\", "/")
|
|
}
|
|
if strconv.Quote(test) != `"`+test+`"` {
|
|
return strconv.Quote(path)
|
|
}
|
|
if forceQuotes {
|
|
return `"` + path + `"`
|
|
}
|
|
return path
|
|
}
|
|
|
|
func quotePath(path string) string {
|
|
return escapePath(path, true)
|
|
}
|
|
|
|
// Color handles terminal colors for bisync
|
|
func Color(style string, s string) string {
|
|
terminal.Start()
|
|
return style + s + terminal.Reset
|
|
}
|
|
|
|
func encode(s string) string {
|
|
return encoder.OS.ToStandardPath(encoder.OS.FromStandardPath(s))
|
|
}
|