2
2
mirror of https://github.com/octoleo/restic.git synced 2024-09-27 22:19:02 +00:00

Rename URI -> Config/Location

This commit is contained in:
Alexander Neumann 2015-12-28 15:57:20 +01:00
parent 566a15285a
commit de933a1d48
7 changed files with 30 additions and 30 deletions

View File

@ -2,7 +2,7 @@ package s3
import "testing"
var uriTests = []struct {
var configTests = []struct {
s string
cfg Config
}{
@ -17,7 +17,7 @@ var uriTests = []struct {
}
func TestParseConfig(t *testing.T) {
for i, test := range uriTests {
for i, test := range configTests {
cfg, err := ParseConfig(test.s)
if err != nil {
t.Errorf("test %d failed: %v", i, err)

View File

@ -2,7 +2,7 @@ package sftp
import "testing"
var uriTests = []struct {
var configTests = []struct {
s string
cfg Config
}{
@ -36,7 +36,7 @@ var uriTests = []struct {
}
func TestParseConfig(t *testing.T) {
for i, test := range uriTests {
for i, test := range configTests {
cfg, err := ParseConfig(test.s)
if err != nil {
t.Errorf("test %d failed: %v", i, err)

View File

@ -1,5 +1,5 @@
// Package uri implements parsing the restic repository location from a string.
package uri
// Package location implements parsing the restic repository location from a string.
package location
import (
"strings"
@ -9,9 +9,9 @@ import (
"github.com/restic/restic/backend/sftp"
)
// URI specifies the location of a repository, including the method of access
// and (possibly) credentials needed for access.
type URI struct {
// Location specifies the location of a repository, including the method of
// access and (possibly) credentials needed for access.
type Location struct {
Scheme string
Config interface{}
}
@ -29,11 +29,11 @@ var parsers = []parser{
{"s3", s3.ParseConfig},
}
// ParseURI parses a repository location from the string s. If s starts with a
// ParseLocation parses a repository location from the string s. If s starts with a
// backend name followed by a colon, that backend's Parse() function is called.
// Otherwise, the local backend is used which interprets s as the name of a
// directory.
func ParseURI(s string) (u URI, err error) {
func ParseLocation(s string) (u Location, err error) {
scheme := extractScheme(s)
u.Scheme = scheme
@ -44,7 +44,7 @@ func ParseURI(s string) (u URI, err error) {
u.Config, err = parser.parse(s)
if err != nil {
return URI{}, err
return Location{}, err
}
return u, nil
@ -54,7 +54,7 @@ func ParseURI(s string) (u URI, err error) {
u.Scheme = "local"
u.Config, err = local.ParseConfig("local:" + s)
if err != nil {
return URI{}, err
return Location{}, err
}
return u, nil

View File

@ -1,4 +1,4 @@
package uri
package location
import (
"reflect"
@ -10,53 +10,53 @@ import (
var parseTests = []struct {
s string
u URI
u Location
}{
{"local:/srv/repo", URI{Scheme: "local", Config: "/srv/repo"}},
{"local:dir1/dir2", URI{Scheme: "local", Config: "dir1/dir2"}},
{"local:dir1/dir2", URI{Scheme: "local", Config: "dir1/dir2"}},
{"dir1/dir2", URI{Scheme: "local", Config: "dir1/dir2"}},
{"local:../dir1/dir2", URI{Scheme: "local", Config: "../dir1/dir2"}},
{"/dir1/dir2", URI{Scheme: "local", Config: "/dir1/dir2"}},
{"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"}},
{"sftp:user@host:/srv/repo", URI{Scheme: "sftp",
{"sftp:user@host:/srv/repo", Location{Scheme: "sftp",
Config: sftp.Config{
User: "user",
Host: "host",
Dir: "/srv/repo",
}}},
{"sftp:host:/srv/repo", URI{Scheme: "sftp",
{"sftp:host:/srv/repo", Location{Scheme: "sftp",
Config: sftp.Config{
User: "",
Host: "host",
Dir: "/srv/repo",
}}},
{"sftp://user@host/srv/repo", URI{Scheme: "sftp",
{"sftp://user@host/srv/repo", Location{Scheme: "sftp",
Config: sftp.Config{
User: "user",
Host: "host",
Dir: "srv/repo",
}}},
{"sftp://user@host//srv/repo", URI{Scheme: "sftp",
{"sftp://user@host//srv/repo", Location{Scheme: "sftp",
Config: sftp.Config{
User: "user",
Host: "host",
Dir: "/srv/repo",
}}},
{"s3://eu-central-1/bucketname", URI{Scheme: "s3",
{"s3://eu-central-1/bucketname", Location{Scheme: "s3",
Config: s3.Config{
Host: "eu-central-1",
Bucket: "bucketname",
}},
},
{"s3://hostname.foo/bucketname", URI{Scheme: "s3",
{"s3://hostname.foo/bucketname", Location{Scheme: "s3",
Config: s3.Config{
Host: "hostname.foo",
Bucket: "bucketname",
}},
},
{"s3:hostname.foo:repo", URI{Scheme: "s3",
{"s3:hostname.foo:repo", Location{Scheme: "s3",
Config: s3.Config{
Host: "hostname.foo",
Bucket: "repo",
@ -64,9 +64,9 @@ var parseTests = []struct {
},
}
func TestParseURI(t *testing.T) {
func TestParseLocation(t *testing.T) {
for i, test := range parseTests {
u, err := ParseURI(test.s)
u, err := ParseLocation(test.s)
if err != nil {
t.Errorf("unexpected error: %v", err)
continue