2015-12-28 14:57:20 +00:00
|
|
|
package location
|
2015-12-28 14:51:24 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/restic/restic/backend/s3"
|
|
|
|
"github.com/restic/restic/backend/sftp"
|
|
|
|
)
|
|
|
|
|
|
|
|
var parseTests = []struct {
|
|
|
|
s string
|
2015-12-28 14:57:20 +00:00
|
|
|
u Location
|
2015-12-28 14:51:24 +00:00
|
|
|
}{
|
2015-12-28 14:57:20 +00:00
|
|
|
{"local:/srv/repo", Location{Scheme: "local", Config: "/srv/repo"}},
|
|
|
|
{"local:dir1/dir2", Location{Scheme: "local", Config: "dir1/dir2"}},
|
|
|
|
{"local:dir1/dir2", Location{Scheme: "local", Config: "dir1/dir2"}},
|
|
|
|
{"dir1/dir2", Location{Scheme: "local", Config: "dir1/dir2"}},
|
|
|
|
{"local:../dir1/dir2", Location{Scheme: "local", Config: "../dir1/dir2"}},
|
|
|
|
{"/dir1/dir2", Location{Scheme: "local", Config: "/dir1/dir2"}},
|
2015-12-28 14:51:24 +00:00
|
|
|
|
2015-12-28 14:57:20 +00:00
|
|
|
{"sftp:user@host:/srv/repo", Location{Scheme: "sftp",
|
2015-12-28 14:51:24 +00:00
|
|
|
Config: sftp.Config{
|
|
|
|
User: "user",
|
|
|
|
Host: "host",
|
|
|
|
Dir: "/srv/repo",
|
|
|
|
}}},
|
2015-12-28 14:57:20 +00:00
|
|
|
{"sftp:host:/srv/repo", Location{Scheme: "sftp",
|
2015-12-28 14:51:24 +00:00
|
|
|
Config: sftp.Config{
|
|
|
|
User: "",
|
|
|
|
Host: "host",
|
|
|
|
Dir: "/srv/repo",
|
|
|
|
}}},
|
2015-12-28 14:57:20 +00:00
|
|
|
{"sftp://user@host/srv/repo", Location{Scheme: "sftp",
|
2015-12-28 14:51:24 +00:00
|
|
|
Config: sftp.Config{
|
|
|
|
User: "user",
|
|
|
|
Host: "host",
|
|
|
|
Dir: "srv/repo",
|
|
|
|
}}},
|
2015-12-28 14:57:20 +00:00
|
|
|
{"sftp://user@host//srv/repo", Location{Scheme: "sftp",
|
2015-12-28 14:51:24 +00:00
|
|
|
Config: sftp.Config{
|
|
|
|
User: "user",
|
|
|
|
Host: "host",
|
|
|
|
Dir: "/srv/repo",
|
|
|
|
}}},
|
|
|
|
|
2015-12-28 14:57:20 +00:00
|
|
|
{"s3://eu-central-1/bucketname", Location{Scheme: "s3",
|
2015-12-28 14:51:24 +00:00
|
|
|
Config: s3.Config{
|
2015-12-28 17:30:42 +00:00
|
|
|
Region: "eu-central-1",
|
2015-12-28 14:51:24 +00:00
|
|
|
Bucket: "bucketname",
|
|
|
|
}},
|
|
|
|
},
|
2015-12-28 14:57:20 +00:00
|
|
|
{"s3://hostname.foo/bucketname", Location{Scheme: "s3",
|
2015-12-28 14:51:24 +00:00
|
|
|
Config: s3.Config{
|
2015-12-28 17:30:42 +00:00
|
|
|
Region: "hostname.foo",
|
2015-12-28 14:51:24 +00:00
|
|
|
Bucket: "bucketname",
|
|
|
|
}},
|
|
|
|
},
|
2015-12-28 23:27:29 +00:00
|
|
|
{"s3:eu-central-1/repo", Location{Scheme: "s3",
|
|
|
|
Config: s3.Config{
|
|
|
|
Region: "eu-central-1",
|
|
|
|
Bucket: "repo",
|
|
|
|
}},
|
|
|
|
},
|
2015-12-28 17:30:42 +00:00
|
|
|
{"s3:https://hostname.foo/repo", Location{Scheme: "s3",
|
2015-12-28 14:51:24 +00:00
|
|
|
Config: s3.Config{
|
2015-12-28 17:30:42 +00:00
|
|
|
URL: "https://hostname.foo",
|
2015-12-28 14:51:24 +00:00
|
|
|
Bucket: "repo",
|
|
|
|
}},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2015-12-28 15:42:44 +00:00
|
|
|
func TestParse(t *testing.T) {
|
2015-12-28 14:51:24 +00:00
|
|
|
for i, test := range parseTests {
|
2015-12-28 15:42:44 +00:00
|
|
|
u, err := Parse(test.s)
|
2015-12-28 14:51:24 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Errorf("unexpected error: %v", err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if test.u.Scheme != u.Scheme {
|
|
|
|
t.Errorf("test %d: scheme does not match, want %q, got %q",
|
|
|
|
i, test.u.Scheme, u.Scheme)
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(test.u.Config, u.Config) {
|
|
|
|
t.Errorf("test %d: cfg map does not match, want:\n %#v\ngot: \n %#v",
|
|
|
|
i, test.u.Config, u.Config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|