2018-01-12 16:30:54 +00:00
|
|
|
package fspath
|
2016-10-23 16:34:17 +00:00
|
|
|
|
|
|
|
import (
|
2021-02-09 09:30:40 +00:00
|
|
|
"flag"
|
2017-02-22 21:24:04 +00:00
|
|
|
"fmt"
|
2021-02-09 09:30:40 +00:00
|
|
|
"os"
|
2020-09-01 16:55:06 +00:00
|
|
|
"path/filepath"
|
2019-09-05 10:01:04 +00:00
|
|
|
"runtime"
|
2016-10-23 16:34:17 +00:00
|
|
|
"testing"
|
|
|
|
|
2021-02-09 09:30:40 +00:00
|
|
|
"github.com/rclone/rclone/fs/config/configmap"
|
2016-10-23 16:34:17 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2021-02-09 09:30:40 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
makeCorpus = flag.Bool("make-corpus", false, "Set to make the fuzzing corpus")
|
2016-10-23 16:34:17 +00:00
|
|
|
)
|
|
|
|
|
2019-09-05 10:01:04 +00:00
|
|
|
func TestCheckConfigName(t *testing.T) {
|
|
|
|
for _, test := range []struct {
|
2022-12-12 19:05:12 +00:00
|
|
|
in string
|
|
|
|
problem error
|
|
|
|
fixed string
|
2019-09-05 10:01:04 +00:00
|
|
|
}{
|
2022-12-12 19:05:12 +00:00
|
|
|
{"remote", nil, "remote"},
|
|
|
|
{"REMOTE", nil, "REMOTE"},
|
|
|
|
{"", errInvalidCharacters, "_"},
|
|
|
|
{":remote:", errInvalidCharacters, "_remote_"},
|
|
|
|
{"remote:", errInvalidCharacters, "remote_"},
|
|
|
|
{"rem:ote", errInvalidCharacters, "rem_ote"},
|
|
|
|
{"rem/ote", errInvalidCharacters, "rem_ote"},
|
|
|
|
{"rem\\ote", errInvalidCharacters, "rem_ote"},
|
|
|
|
{"[remote", errInvalidCharacters, "_remote"},
|
|
|
|
{"*", errInvalidCharacters, "_"},
|
|
|
|
{"-remote", errInvalidCharacters, "_remote"},
|
|
|
|
{"r-emote-", nil, "r-emote-"},
|
|
|
|
{"---rem:::ote???", errInvalidCharacters, "_rem_ote_"},
|
|
|
|
{"_rem_ote_", nil, "_rem_ote_"},
|
|
|
|
{".", nil, "."},
|
|
|
|
{"..", nil, ".."},
|
|
|
|
{".r.e.m.o.t.e.", nil, ".r.e.m.o.t.e."},
|
|
|
|
{"rem ote", nil, "rem ote"},
|
2023-01-19 20:38:24 +00:00
|
|
|
{"user@example.com", nil, "user@example.com"},
|
|
|
|
{"user+junkmail@example.com", nil, "user+junkmail@example.com"},
|
2022-12-12 19:05:12 +00:00
|
|
|
{"blåbær", nil, "blåbær"},
|
|
|
|
{"chữ Quốc ngữ", nil, "chữ Quốc ngữ"},
|
|
|
|
{"remote ", errInvalidCharacters, "remote_"},
|
|
|
|
{" remote", errInvalidCharacters, "_remote"},
|
|
|
|
{" remote ", errInvalidCharacters, "_remote_"},
|
2019-09-05 10:01:04 +00:00
|
|
|
} {
|
2022-12-12 19:05:12 +00:00
|
|
|
problem := CheckConfigName(test.in)
|
|
|
|
assert.Equal(t, test.problem, problem, test.in)
|
|
|
|
fixed := MakeConfigName(test.in)
|
|
|
|
assert.Equal(t, test.fixed, fixed, test.in)
|
2019-09-05 10:01:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckRemoteName(t *testing.T) {
|
|
|
|
for _, test := range []struct {
|
|
|
|
in string
|
|
|
|
want error
|
|
|
|
}{
|
|
|
|
{":remote:", nil},
|
2022-12-10 14:53:42 +00:00
|
|
|
{":REMOTE:", nil},
|
2021-02-09 09:30:40 +00:00
|
|
|
{":s3:", nil},
|
2019-09-05 10:01:04 +00:00
|
|
|
{"remote:", nil},
|
2021-11-01 19:50:06 +00:00
|
|
|
{".:", nil},
|
|
|
|
{"..:", nil},
|
|
|
|
{".r.e.m.o.t.e.:", nil},
|
2022-12-12 19:03:39 +00:00
|
|
|
{"-r-emote-:", errInvalidCharacters},
|
2022-09-16 14:11:54 +00:00
|
|
|
{"rem ote:", nil},
|
2023-01-19 20:38:24 +00:00
|
|
|
{"user@example.com:", nil},
|
|
|
|
{"user+junkmail@example.com:", nil},
|
2022-12-10 14:53:42 +00:00
|
|
|
{"blåbær:", nil},
|
|
|
|
{"chữ Quốc ngữ:", nil},
|
2022-09-16 14:57:49 +00:00
|
|
|
{"remote :", errInvalidCharacters},
|
|
|
|
{" remote:", errInvalidCharacters},
|
|
|
|
{" remote :", errInvalidCharacters},
|
2019-09-05 10:01:04 +00:00
|
|
|
{"", errInvalidCharacters},
|
|
|
|
{"rem:ote", errInvalidCharacters},
|
|
|
|
{"rem:ote:", errInvalidCharacters},
|
|
|
|
{"remote", errInvalidCharacters},
|
|
|
|
{"rem/ote:", errInvalidCharacters},
|
|
|
|
{"rem\\ote:", errInvalidCharacters},
|
|
|
|
{"[remote:", errInvalidCharacters},
|
|
|
|
{"*:", errInvalidCharacters},
|
|
|
|
} {
|
2021-02-09 09:30:40 +00:00
|
|
|
got := checkRemoteName(test.in)
|
2019-09-05 10:01:04 +00:00
|
|
|
assert.Equal(t, test.want, got, test.in)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 09:39:00 +00:00
|
|
|
func TestParse(t *testing.T) {
|
2021-02-09 09:30:40 +00:00
|
|
|
for testNumber, test := range []struct {
|
|
|
|
in string
|
|
|
|
wantParsed Parsed
|
|
|
|
wantErr error
|
2021-03-22 16:25:19 +00:00
|
|
|
win bool // only run these tests on Windows
|
|
|
|
noWin bool // only run these tests on !Windows
|
2018-06-18 09:39:00 +00:00
|
|
|
}{
|
2021-02-09 09:30:40 +00:00
|
|
|
{
|
|
|
|
in: "",
|
|
|
|
wantErr: errCantBeEmpty,
|
|
|
|
}, {
|
|
|
|
in: ":",
|
|
|
|
wantErr: errConfigName,
|
|
|
|
}, {
|
|
|
|
in: "::",
|
|
|
|
wantErr: errConfigNameEmpty,
|
|
|
|
}, {
|
|
|
|
in: ":/:",
|
|
|
|
wantErr: errInvalidCharacters,
|
|
|
|
}, {
|
|
|
|
in: "/:",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "/:",
|
|
|
|
},
|
2021-03-22 16:25:19 +00:00
|
|
|
}, {
|
|
|
|
in: "\\backslash:",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "/backslash:",
|
|
|
|
},
|
|
|
|
win: true,
|
2021-02-09 09:30:40 +00:00
|
|
|
}, {
|
|
|
|
in: "\\backslash:",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "\\backslash:",
|
|
|
|
},
|
2021-03-22 16:25:19 +00:00
|
|
|
noWin: true,
|
2021-02-09 09:30:40 +00:00
|
|
|
}, {
|
|
|
|
in: "/slash:",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "/slash:",
|
|
|
|
},
|
2021-03-22 16:25:19 +00:00
|
|
|
}, {
|
|
|
|
in: "with\\backslash:",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "with/backslash:",
|
|
|
|
},
|
|
|
|
win: true,
|
2021-02-09 09:30:40 +00:00
|
|
|
}, {
|
|
|
|
in: "with\\backslash:",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "with\\backslash:",
|
|
|
|
},
|
2021-03-22 16:25:19 +00:00
|
|
|
noWin: true,
|
2021-02-09 09:30:40 +00:00
|
|
|
}, {
|
|
|
|
in: "with/slash:",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "with/slash:",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: "/path/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: "/path:/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "/path:/to/file",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: "./path:/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "./path:/to/file",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: "./:colon.txt",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "./:colon.txt",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: "path/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "",
|
|
|
|
Path: "path/to/file",
|
|
|
|
},
|
2021-11-01 19:50:06 +00:00
|
|
|
}, {
|
|
|
|
in: ".:",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: ".",
|
|
|
|
Name: ".",
|
|
|
|
Path: "",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: "..:",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "..",
|
|
|
|
Name: "..",
|
|
|
|
Path: "",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: ".:colon.txt",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: ".",
|
|
|
|
Name: ".",
|
|
|
|
Path: "colon.txt",
|
|
|
|
},
|
2021-02-09 09:30:40 +00:00
|
|
|
}, {
|
|
|
|
in: "remote:path/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "remote",
|
|
|
|
Name: "remote",
|
|
|
|
Path: "path/to/file",
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: "rem*ote:path/to/file",
|
|
|
|
wantErr: errInvalidCharacters,
|
|
|
|
}, {
|
|
|
|
in: "remote:/path/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "remote",
|
|
|
|
Name: "remote",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
},
|
|
|
|
}, {
|
2021-11-01 19:50:06 +00:00
|
|
|
in: "rem.ote:/path/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "rem.ote",
|
|
|
|
Name: "rem.ote",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
},
|
2022-09-16 14:11:54 +00:00
|
|
|
}, {
|
|
|
|
in: "rem ote:/path/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: "rem ote",
|
|
|
|
Name: "rem ote",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
},
|
|
|
|
}, {
|
2022-09-16 14:57:49 +00:00
|
|
|
in: "remote :/path/to/file",
|
|
|
|
wantErr: errInvalidCharacters,
|
2022-09-16 14:11:54 +00:00
|
|
|
}, {
|
2022-09-16 14:57:49 +00:00
|
|
|
in: " remote:/path/to/file",
|
|
|
|
wantErr: errInvalidCharacters,
|
2022-09-16 14:11:54 +00:00
|
|
|
}, {
|
2022-09-16 14:57:49 +00:00
|
|
|
in: " remote :/path/to/file",
|
|
|
|
wantErr: errInvalidCharacters,
|
2021-11-01 19:50:06 +00:00
|
|
|
}, {
|
|
|
|
in: "rem#ote:/path/to/file",
|
2021-02-09 09:30:40 +00:00
|
|
|
wantErr: errInvalidCharacters,
|
|
|
|
}, {
|
|
|
|
in: ":backend:/path/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: ":backend",
|
|
|
|
Name: ":backend",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
},
|
2021-11-01 19:50:06 +00:00
|
|
|
}, {
|
|
|
|
in: ":back.end:/path/to/file",
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: ":back.end",
|
|
|
|
Name: ":back.end",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
},
|
2021-02-09 09:30:40 +00:00
|
|
|
}, {
|
|
|
|
in: ":bac*kend:/path/to/file",
|
|
|
|
wantErr: errInvalidCharacters,
|
|
|
|
}, {
|
|
|
|
in: `C:\path\to\file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "",
|
2021-03-22 16:25:19 +00:00
|
|
|
Path: `C:/path/to/file`,
|
|
|
|
},
|
|
|
|
win: true,
|
|
|
|
}, {
|
|
|
|
in: `C:\path\to\file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "C",
|
|
|
|
ConfigString: "C",
|
|
|
|
Path: `\path\to\file`,
|
|
|
|
},
|
|
|
|
noWin: true,
|
|
|
|
}, {
|
|
|
|
in: `\path\to\file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "",
|
|
|
|
Path: `/path/to/file`,
|
|
|
|
},
|
|
|
|
win: true,
|
|
|
|
}, {
|
|
|
|
in: `\path\to\file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "",
|
|
|
|
Path: `\path\to\file`,
|
2021-02-09 09:30:40 +00:00
|
|
|
},
|
2021-03-22 16:25:19 +00:00
|
|
|
noWin: true,
|
2021-11-01 19:50:06 +00:00
|
|
|
}, {
|
|
|
|
in: `.`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "",
|
|
|
|
Path: `.`,
|
|
|
|
},
|
|
|
|
noWin: true,
|
|
|
|
}, {
|
|
|
|
in: `..`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "",
|
|
|
|
Path: `..`,
|
|
|
|
},
|
|
|
|
noWin: true,
|
2021-03-22 16:25:19 +00:00
|
|
|
}, {
|
|
|
|
in: `remote:\path\to\file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "remote",
|
|
|
|
ConfigString: "remote",
|
|
|
|
Path: `/path/to/file`,
|
|
|
|
},
|
|
|
|
win: true,
|
2021-02-09 09:30:40 +00:00
|
|
|
}, {
|
|
|
|
in: `remote:\path\to\file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "remote",
|
|
|
|
ConfigString: "remote",
|
|
|
|
Path: `\path\to\file`,
|
|
|
|
},
|
2021-03-22 16:25:19 +00:00
|
|
|
noWin: true,
|
|
|
|
}, {
|
|
|
|
in: `D:/path/to/file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "",
|
|
|
|
Path: `D:/path/to/file`,
|
|
|
|
},
|
|
|
|
win: true,
|
2021-02-09 09:30:40 +00:00
|
|
|
}, {
|
|
|
|
in: `D:/path/to/file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
Name: "D",
|
|
|
|
ConfigString: "D",
|
|
|
|
Path: `/path/to/file`,
|
|
|
|
},
|
2021-03-22 16:25:19 +00:00
|
|
|
noWin: true,
|
2021-02-09 09:30:40 +00:00
|
|
|
}, {
|
|
|
|
in: `:backend,param1:/path/to/file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: `:backend,param1`,
|
|
|
|
Name: ":backend",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
Config: configmap.Simple{
|
|
|
|
"param1": "true",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: `:backend,param1=value:/path/to/file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: `:backend,param1=value`,
|
|
|
|
Name: ":backend",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
Config: configmap.Simple{
|
|
|
|
"param1": "value",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: `:backend,param1=value1,param2,param3=value3:/path/to/file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: `:backend,param1=value1,param2,param3=value3`,
|
|
|
|
Name: ":backend",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
Config: configmap.Simple{
|
|
|
|
"param1": "value1",
|
|
|
|
"param2": "true",
|
|
|
|
"param3": "value3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: `:backend,param1=value1,param2="value2",param3='value3':/path/to/file`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: `:backend,param1=value1,param2="value2",param3='value3'`,
|
|
|
|
Name: ":backend",
|
|
|
|
Path: "/path/to/file",
|
|
|
|
Config: configmap.Simple{
|
|
|
|
"param1": "value1",
|
|
|
|
"param2": "value2",
|
|
|
|
"param3": "value3",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: `:backend,param-1=value:/path/to/file`,
|
|
|
|
wantErr: errBadConfigParam,
|
|
|
|
}, {
|
|
|
|
in: `:backend,param1="value"x:/path/to/file`,
|
|
|
|
wantErr: errAfterQuote,
|
|
|
|
}, {
|
|
|
|
in: `:backend,`,
|
|
|
|
wantErr: errParam,
|
|
|
|
}, {
|
|
|
|
in: `:backend,param=value`,
|
|
|
|
wantErr: errValue,
|
|
|
|
}, {
|
|
|
|
in: `:backend,param="value'`,
|
|
|
|
wantErr: errQuotedValue,
|
|
|
|
}, {
|
|
|
|
in: `:backend,param1="value"`,
|
|
|
|
wantErr: errAfterQuote,
|
|
|
|
}, {
|
|
|
|
in: `:backend,=value:`,
|
|
|
|
wantErr: errEmptyConfigParam,
|
|
|
|
}, {
|
|
|
|
in: `:backend,:`,
|
|
|
|
wantErr: errEmptyConfigParam,
|
|
|
|
}, {
|
|
|
|
in: `:backend,,:`,
|
|
|
|
wantErr: errEmptyConfigParam,
|
|
|
|
}, {
|
|
|
|
in: `:backend,param=:path`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: `:backend,param=`,
|
|
|
|
Name: ":backend",
|
|
|
|
Path: "path",
|
|
|
|
Config: configmap.Simple{
|
|
|
|
"param": "",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: `:backend,param="with""quote":path`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: `:backend,param="with""quote"`,
|
|
|
|
Name: ":backend",
|
|
|
|
Path: "path",
|
|
|
|
Config: configmap.Simple{
|
|
|
|
"param": `with"quote`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: `:backend,param='''''':`,
|
|
|
|
wantParsed: Parsed{
|
|
|
|
ConfigString: `:backend,param=''''''`,
|
|
|
|
Name: ":backend",
|
|
|
|
Path: "",
|
|
|
|
Config: configmap.Simple{
|
|
|
|
"param": `''`,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, {
|
|
|
|
in: `:backend,param=''bad'':`,
|
|
|
|
wantErr: errAfterQuote,
|
|
|
|
},
|
2018-06-18 09:39:00 +00:00
|
|
|
} {
|
2021-02-09 09:30:40 +00:00
|
|
|
gotParsed, gotErr := Parse(test.in)
|
2021-03-22 16:25:19 +00:00
|
|
|
if runtime.GOOS == "windows" && test.noWin {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if runtime.GOOS != "windows" && test.win {
|
|
|
|
continue
|
2021-02-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
assert.Equal(t, test.wantErr, gotErr, test.in)
|
|
|
|
if test.wantErr == nil {
|
|
|
|
assert.Equal(t, test.wantParsed, gotParsed, test.in)
|
2019-09-05 10:01:04 +00:00
|
|
|
}
|
2021-02-09 09:30:40 +00:00
|
|
|
if *makeCorpus {
|
|
|
|
// write the test corpus for fuzzing
|
|
|
|
require.NoError(t, os.MkdirAll("corpus", 0777))
|
2022-08-20 14:38:02 +00:00
|
|
|
require.NoError(t, os.WriteFile(fmt.Sprintf("corpus/%02d", testNumber), []byte(test.in), 0666))
|
2021-02-09 09:30:40 +00:00
|
|
|
}
|
|
|
|
|
2018-06-18 09:39:00 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-23 16:34:17 +00:00
|
|
|
|
2021-02-10 14:26:30 +00:00
|
|
|
func TestSplitFs(t *testing.T) {
|
|
|
|
for _, test := range []struct {
|
|
|
|
remote, wantRemoteName, wantRemotePath string
|
|
|
|
wantErr error
|
|
|
|
}{
|
|
|
|
{"", "", "", errCantBeEmpty},
|
|
|
|
|
|
|
|
{"remote:", "remote:", "", nil},
|
|
|
|
{"remote:potato", "remote:", "potato", nil},
|
|
|
|
{"remote:/", "remote:", "/", nil},
|
|
|
|
{"remote:/potato", "remote:", "/potato", nil},
|
|
|
|
{"remote:/potato/potato", "remote:", "/potato/potato", nil},
|
|
|
|
{"remote:potato/sausage", "remote:", "potato/sausage", nil},
|
2021-11-01 19:50:06 +00:00
|
|
|
{"rem.ote:potato/sausage", "rem.ote:", "potato/sausage", nil},
|
|
|
|
|
2022-09-16 14:11:54 +00:00
|
|
|
{"rem ote:", "rem ote:", "", nil},
|
2022-09-16 14:57:49 +00:00
|
|
|
{"remote :", "", "", errInvalidCharacters},
|
|
|
|
{" remote:", "", "", errInvalidCharacters},
|
|
|
|
{" remote :", "", "", errInvalidCharacters},
|
2022-09-16 14:11:54 +00:00
|
|
|
|
2021-11-01 19:50:06 +00:00
|
|
|
{".:", ".:", "", nil},
|
|
|
|
{"..:", "..:", "", nil},
|
|
|
|
{".:potato/sausage", ".:", "potato/sausage", nil},
|
|
|
|
{"..:potato/sausage", "..:", "potato/sausage", nil},
|
2021-02-10 14:26:30 +00:00
|
|
|
|
|
|
|
{":remote:", ":remote:", "", nil},
|
|
|
|
{":remote:potato", ":remote:", "potato", nil},
|
|
|
|
{":remote:/", ":remote:", "/", nil},
|
|
|
|
{":remote:/potato", ":remote:", "/potato", nil},
|
|
|
|
{":remote:/potato/potato", ":remote:", "/potato/potato", nil},
|
|
|
|
{":remote:potato/sausage", ":remote:", "potato/sausage", nil},
|
2021-11-01 19:50:06 +00:00
|
|
|
{":rem.ote:potato/sausage", ":rem.ote:", "potato/sausage", nil},
|
2021-02-10 14:26:30 +00:00
|
|
|
{":rem[ote:potato/sausage", "", "", errInvalidCharacters},
|
|
|
|
|
2021-11-01 19:50:06 +00:00
|
|
|
{":.:", ":.:", "", nil},
|
|
|
|
{":..:", ":..:", "", nil},
|
|
|
|
{":.:potato/sausage", ":.:", "potato/sausage", nil},
|
|
|
|
{":..:potato/sausage", ":..:", "potato/sausage", nil},
|
|
|
|
|
2021-02-10 14:26:30 +00:00
|
|
|
{"/", "", "/", nil},
|
|
|
|
{"/root", "", "/root", nil},
|
|
|
|
{"/a/b", "", "/a/b", nil},
|
|
|
|
{"root", "", "root", nil},
|
|
|
|
{"a/b", "", "a/b", nil},
|
|
|
|
{"root/", "", "root/", nil},
|
|
|
|
{"a/b/", "", "a/b/", nil},
|
|
|
|
} {
|
|
|
|
gotRemoteName, gotRemotePath, gotErr := SplitFs(test.remote)
|
|
|
|
assert.Equal(t, test.wantErr, gotErr)
|
|
|
|
assert.Equal(t, test.wantRemoteName, gotRemoteName, test.remote)
|
|
|
|
assert.Equal(t, test.wantRemotePath, gotRemotePath, test.remote)
|
|
|
|
if gotErr == nil {
|
|
|
|
assert.Equal(t, test.remote, gotRemoteName+gotRemotePath, fmt.Sprintf("%s: %q + %q != %q", test.remote, gotRemoteName, gotRemotePath, test.remote))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-18 09:39:00 +00:00
|
|
|
func TestSplit(t *testing.T) {
|
2016-10-23 16:34:17 +00:00
|
|
|
for _, test := range []struct {
|
|
|
|
remote, wantParent, wantLeaf string
|
2019-09-05 10:01:04 +00:00
|
|
|
wantErr error
|
2016-10-23 16:34:17 +00:00
|
|
|
}{
|
2020-05-19 11:34:23 +00:00
|
|
|
{"", "", "", errCantBeEmpty},
|
2018-08-07 21:51:06 +00:00
|
|
|
|
2019-09-05 10:01:04 +00:00
|
|
|
{"remote:", "remote:", "", nil},
|
|
|
|
{"remote:potato", "remote:", "potato", nil},
|
|
|
|
{"remote:/", "remote:/", "", nil},
|
|
|
|
{"remote:/potato", "remote:/", "potato", nil},
|
|
|
|
{"remote:/potato/potato", "remote:/potato/", "potato", nil},
|
|
|
|
{"remote:potato/sausage", "remote:potato/", "sausage", nil},
|
2021-11-01 19:50:06 +00:00
|
|
|
{"rem.ote:potato/sausage", "rem.ote:potato/", "sausage", nil},
|
|
|
|
|
2022-09-16 14:11:54 +00:00
|
|
|
{"rem ote:", "rem ote:", "", nil},
|
2022-09-16 14:57:49 +00:00
|
|
|
{"remote :", "", "", errInvalidCharacters},
|
|
|
|
{" remote:", "", "", errInvalidCharacters},
|
|
|
|
{" remote :", "", "", errInvalidCharacters},
|
2022-09-16 14:11:54 +00:00
|
|
|
|
2021-11-01 19:50:06 +00:00
|
|
|
{".:", ".:", "", nil},
|
|
|
|
{"..:", "..:", "", nil},
|
|
|
|
{".:potato/sausage", ".:potato/", "sausage", nil},
|
|
|
|
{"..:potato/sausage", "..:potato/", "sausage", nil},
|
2018-08-07 21:51:06 +00:00
|
|
|
|
2019-09-05 10:01:04 +00:00
|
|
|
{":remote:", ":remote:", "", nil},
|
|
|
|
{":remote:potato", ":remote:", "potato", nil},
|
|
|
|
{":remote:/", ":remote:/", "", nil},
|
|
|
|
{":remote:/potato", ":remote:/", "potato", nil},
|
|
|
|
{":remote:/potato/potato", ":remote:/potato/", "potato", nil},
|
|
|
|
{":remote:potato/sausage", ":remote:potato/", "sausage", nil},
|
2021-11-01 19:50:06 +00:00
|
|
|
{":rem.ote:potato/sausage", ":rem.ote:potato/", "sausage", nil},
|
2019-09-05 10:01:04 +00:00
|
|
|
{":rem[ote:potato/sausage", "", "", errInvalidCharacters},
|
2018-08-07 21:51:06 +00:00
|
|
|
|
2021-11-01 19:50:06 +00:00
|
|
|
{":.:", ":.:", "", nil},
|
|
|
|
{":..:", ":..:", "", nil},
|
|
|
|
{":.:potato/sausage", ":.:potato/", "sausage", nil},
|
|
|
|
{":..:potato/sausage", ":..:potato/", "sausage", nil},
|
|
|
|
|
2019-09-05 10:01:04 +00:00
|
|
|
{"/", "/", "", nil},
|
|
|
|
{"/root", "/", "root", nil},
|
|
|
|
{"/a/b", "/a/", "b", nil},
|
|
|
|
{"root", "", "root", nil},
|
|
|
|
{"a/b", "a/", "b", nil},
|
|
|
|
{"root/", "root/", "", nil},
|
|
|
|
{"a/b/", "a/b/", "", nil},
|
2016-10-23 16:34:17 +00:00
|
|
|
} {
|
2019-09-05 10:01:04 +00:00
|
|
|
gotParent, gotLeaf, gotErr := Split(test.remote)
|
|
|
|
assert.Equal(t, test.wantErr, gotErr)
|
2016-10-23 16:34:17 +00:00
|
|
|
assert.Equal(t, test.wantParent, gotParent, test.remote)
|
|
|
|
assert.Equal(t, test.wantLeaf, gotLeaf, test.remote)
|
2019-09-05 10:01:04 +00:00
|
|
|
if gotErr == nil {
|
|
|
|
assert.Equal(t, test.remote, gotParent+gotLeaf, fmt.Sprintf("%s: %q + %q != %q", test.remote, gotParent, gotLeaf, test.remote))
|
|
|
|
}
|
2016-10-23 16:34:17 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-13 10:26:13 +00:00
|
|
|
|
|
|
|
func TestMakeAbsolute(t *testing.T) {
|
|
|
|
for _, test := range []struct {
|
|
|
|
in string
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{"", ""},
|
|
|
|
{".", ""},
|
|
|
|
{"/.", "/"},
|
|
|
|
{"../potato", "potato"},
|
|
|
|
{"/../potato", "/potato"},
|
|
|
|
{"./../potato", "potato"},
|
|
|
|
{"//../potato", "/potato"},
|
|
|
|
{"././../potato", "potato"},
|
|
|
|
{"././potato/../../onion", "onion"},
|
|
|
|
} {
|
|
|
|
got := makeAbsolute(test.in)
|
|
|
|
assert.Equal(t, test.want, got, test)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-09 11:35:27 +00:00
|
|
|
func TestJoinRootPath(t *testing.T) {
|
|
|
|
for _, test := range []struct {
|
2020-12-13 10:26:13 +00:00
|
|
|
remote string
|
|
|
|
filePath string
|
2018-10-09 11:35:27 +00:00
|
|
|
want string
|
|
|
|
}{
|
2020-12-13 10:26:13 +00:00
|
|
|
{"", "", ""},
|
|
|
|
{"", "/", "/"},
|
|
|
|
{"/", "", "/"},
|
|
|
|
{"/", "/", "/"},
|
|
|
|
{"/", "//", "/"},
|
|
|
|
{"/root", "", "/root"},
|
|
|
|
{"/root", "/", "/root"},
|
|
|
|
{"/root", "//", "/root"},
|
|
|
|
{"/a/b", "", "/a/b"},
|
|
|
|
{"//", "/", "//"},
|
|
|
|
{"//server", "path", "//server/path"},
|
|
|
|
{"//server/sub", "path", "//server/sub/path"},
|
|
|
|
{"//server", "//path", "//server/path"},
|
|
|
|
{"//server/sub", "//path", "//server/sub/path"},
|
|
|
|
{"//", "/", "//"},
|
|
|
|
{"//server", "path", "//server/path"},
|
|
|
|
{"//server/sub", "path", "//server/sub/path"},
|
|
|
|
{"//server", "//path", "//server/path"},
|
|
|
|
{"//server/sub", "//path", "//server/sub/path"},
|
|
|
|
{filepath.FromSlash("//server/sub"), filepath.FromSlash("//path"), "//server/sub/path"},
|
|
|
|
{"s3:", "", "s3:"},
|
|
|
|
{"s3:", ".", "s3:"},
|
|
|
|
{"s3:.", ".", "s3:"},
|
|
|
|
{"s3:", "..", "s3:"},
|
|
|
|
{"s3:dir", "sub", "s3:dir/sub"},
|
|
|
|
{"s3:dir", "/sub", "s3:dir/sub"},
|
|
|
|
{"s3:dir", "./sub", "s3:dir/sub"},
|
|
|
|
{"s3:/dir", "/sub/", "s3:/dir/sub"},
|
|
|
|
{"s3:dir", "..", "s3:dir"},
|
|
|
|
{"s3:dir", "/..", "s3:dir"},
|
|
|
|
{"s3:dir", "/../", "s3:dir"},
|
2018-10-09 11:35:27 +00:00
|
|
|
} {
|
2020-12-13 10:26:13 +00:00
|
|
|
got := JoinRootPath(test.remote, test.filePath)
|
|
|
|
assert.Equal(t, test.want, got, test)
|
2018-10-09 11:35:27 +00:00
|
|
|
}
|
|
|
|
}
|