2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-25 12:09:59 +00:00
restic/backend/sftp/config_test.go
2016-01-17 18:48:05 +01:00

53 lines
1017 B
Go

package sftp
import "testing"
var configTests = []struct {
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) {
for i, test := range configTests {
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
}
}
}