2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-25 20:11:06 +00:00
restic/location/location_test.go

99 lines
2.3 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{
2016-01-02 14:33:17 +00:00
Endpoint: "eu-central-1",
Bucket: "bucketname",
2015-12-28 14:51:24 +00:00
}},
},
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{
2016-01-02 14:33:17 +00:00
Endpoint: "hostname.foo",
Bucket: "bucketname",
2015-12-28 14:51:24 +00:00
}},
},
2015-12-28 23:27:29 +00:00
{"s3:eu-central-1/repo", Location{Scheme: "s3",
Config: s3.Config{
2016-01-02 14:33:17 +00:00
Endpoint: "eu-central-1",
Bucket: "repo",
2015-12-28 23:27:29 +00:00
}},
},
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{
2016-01-02 14:33:17 +00:00
Endpoint: "hostname.foo",
Bucket: "repo",
}},
},
{"s3:http://hostname.foo/repo", Location{Scheme: "s3",
Config: s3.Config{
Endpoint: "hostname.foo",
Bucket: "repo",
UseHTTP: true,
2015-12-28 14:51:24 +00:00
}},
},
}
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)
}
}
}