restic/location/location_test.go

86 lines
2 KiB
Go
Raw Normal View History

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{
Host: "eu-central-1",
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{
Host: "hostname.foo",
Bucket: "bucketname",
}},
},
2015-12-28 14:57:20 +00:00
{"s3:hostname.foo:repo", Location{Scheme: "s3",
2015-12-28 14:51:24 +00:00
Config: s3.Config{
Host: "hostname.foo",
Bucket: "repo",
}},
},
}
2015-12-28 14:57:20 +00:00
func TestParseLocation(t *testing.T) {
2015-12-28 14:51:24 +00:00
for i, test := range parseTests {
2015-12-28 14:57:20 +00:00
u, err := ParseLocation(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)
}
}
}