Files
kopia/internal/atomicfile/atomicfile_test.go
2021-06-08 20:11:43 -07:00

45 lines
1.4 KiB
Go

package atomicfile
import (
"runtime"
"strings"
"testing"
)
var veryLongSegment = strings.Repeat("f", 270)
func TestMaybePrefixLongFilenameOnWindows(t *testing.T) {
if runtime.GOOS != "windows" {
return
}
cases := []struct {
input string
want string
}{
// too short
{"C:\\Short.txt", "C:\\Short.txt"},
// long paths
{"C:\\" + veryLongSegment + "\\foo", "\\\\?\\C:\\" + veryLongSegment + "\\foo"},
{"C:\\" + veryLongSegment + "/foo/bar", "\\\\?\\C:\\" + veryLongSegment + "\\foo\\bar"},
{"C:\\" + veryLongSegment + "/foo/./././bar", "\\\\?\\C:\\" + veryLongSegment + "\\foo\\bar"},
{"C:\\" + veryLongSegment + "\\.\\foo", "\\\\?\\C:\\" + veryLongSegment + "\\foo"},
{"C:\\" + veryLongSegment + "/.\\foo", "\\\\?\\C:\\" + veryLongSegment + "\\foo"},
{"C:\\" + veryLongSegment + "\\./foo", "\\\\?\\C:\\" + veryLongSegment + "\\foo"},
{"\\\\?\\C:\\" + veryLongSegment + "\\foo", "\\\\?\\C:\\" + veryLongSegment + "\\foo"},
// relative
{veryLongSegment + "\\foo", veryLongSegment + "\\foo"},
{"./" + veryLongSegment + "\\foo", "./" + veryLongSegment + "\\foo"},
{"../../" + veryLongSegment + "\\foo", "../../" + veryLongSegment + "\\foo"},
{"..\\..\\" + veryLongSegment + "\\foo", "..\\..\\" + veryLongSegment + "\\foo"},
}
for _, tc := range cases {
if got := MaybePrefixLongFilenameOnWindows(tc.input); got != tc.want {
t.Errorf("invalid result for %v: got %v, want %v", tc.input, got, tc.want)
}
}
}