restic/backend/sftp/config_test.go

53 lines
1,017 B
Go
Raw Normal View History

2015-12-28 14:51:24 +00:00
package sftp
import "testing"
2015-12-28 14:57:20 +00:00
var configTests = []struct {
2015-12-28 14:51:24 +00:00
s string
cfg Config
}{
// first form, user specified sftp://user@host/dir
{
"sftp://user@host/dir/subdir",
Config{User: "user", Host: "host", Dir: "dir/subdir"},
},
{
"sftp://host/dir/subdir",
Config{Host: "host", Dir: "dir/subdir"},
},
{
"sftp://host//dir/subdir",
Config{Host: "host", Dir: "/dir/subdir"},
},
// second form, user specified sftp:user@host:/dir
{
"sftp:foo@bar:/baz/quux",
Config{User: "foo", Host: "bar", Dir: "/baz/quux"},
},
{
"sftp:bar:../baz/quux",
Config{Host: "bar", Dir: "../baz/quux"},
},
{
"sftp:fux@bar:baz/qu:ux",
Config{User: "fux", Host: "bar", Dir: "baz/qu:ux"},
},
}
func TestParseConfig(t *testing.T) {
2015-12-28 14:57:20 +00:00
for i, test := range configTests {
2015-12-28 14:51:24 +00:00
cfg, err := ParseConfig(test.s)
if err != nil {
t.Errorf("test %d failed: %v", i, err)
continue
}
if cfg != test.cfg {
t.Errorf("test %d: wrong config, want:\n %v\ngot:\n %v",
i, test.cfg, cfg)
continue
}
}
}