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:
parent
566a15285a
commit
de933a1d48
@ -2,7 +2,7 @@ package s3
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
var uriTests = []struct {
|
var configTests = []struct {
|
||||||
s string
|
s string
|
||||||
cfg Config
|
cfg Config
|
||||||
}{
|
}{
|
||||||
@ -17,7 +17,7 @@ var uriTests = []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseConfig(t *testing.T) {
|
func TestParseConfig(t *testing.T) {
|
||||||
for i, test := range uriTests {
|
for i, test := range configTests {
|
||||||
cfg, err := ParseConfig(test.s)
|
cfg, err := ParseConfig(test.s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("test %d failed: %v", i, err)
|
t.Errorf("test %d failed: %v", i, err)
|
@ -2,7 +2,7 @@ package sftp
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
var uriTests = []struct {
|
var configTests = []struct {
|
||||||
s string
|
s string
|
||||||
cfg Config
|
cfg Config
|
||||||
}{
|
}{
|
||||||
@ -36,7 +36,7 @@ var uriTests = []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseConfig(t *testing.T) {
|
func TestParseConfig(t *testing.T) {
|
||||||
for i, test := range uriTests {
|
for i, test := range configTests {
|
||||||
cfg, err := ParseConfig(test.s)
|
cfg, err := ParseConfig(test.s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("test %d failed: %v", i, err)
|
t.Errorf("test %d failed: %v", i, err)
|
@ -1,5 +1,5 @@
|
|||||||
// Package uri implements parsing the restic repository location from a string.
|
// Package location implements parsing the restic repository location from a string.
|
||||||
package uri
|
package location
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
@ -9,9 +9,9 @@ import (
|
|||||||
"github.com/restic/restic/backend/sftp"
|
"github.com/restic/restic/backend/sftp"
|
||||||
)
|
)
|
||||||
|
|
||||||
// URI specifies the location of a repository, including the method of access
|
// Location specifies the location of a repository, including the method of
|
||||||
// and (possibly) credentials needed for access.
|
// access and (possibly) credentials needed for access.
|
||||||
type URI struct {
|
type Location struct {
|
||||||
Scheme string
|
Scheme string
|
||||||
Config interface{}
|
Config interface{}
|
||||||
}
|
}
|
||||||
@ -29,11 +29,11 @@ var parsers = []parser{
|
|||||||
{"s3", s3.ParseConfig},
|
{"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.
|
// 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
|
// Otherwise, the local backend is used which interprets s as the name of a
|
||||||
// directory.
|
// directory.
|
||||||
func ParseURI(s string) (u URI, err error) {
|
func ParseLocation(s string) (u Location, err error) {
|
||||||
scheme := extractScheme(s)
|
scheme := extractScheme(s)
|
||||||
u.Scheme = scheme
|
u.Scheme = scheme
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ func ParseURI(s string) (u URI, err error) {
|
|||||||
|
|
||||||
u.Config, err = parser.parse(s)
|
u.Config, err = parser.parse(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return URI{}, err
|
return Location{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return u, nil
|
return u, nil
|
||||||
@ -54,7 +54,7 @@ func ParseURI(s string) (u URI, err error) {
|
|||||||
u.Scheme = "local"
|
u.Scheme = "local"
|
||||||
u.Config, err = local.ParseConfig("local:" + s)
|
u.Config, err = local.ParseConfig("local:" + s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return URI{}, err
|
return Location{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return u, nil
|
return u, nil
|
@ -1,4 +1,4 @@
|
|||||||
package uri
|
package location
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -10,53 +10,53 @@ import (
|
|||||||
|
|
||||||
var parseTests = []struct {
|
var parseTests = []struct {
|
||||||
s string
|
s string
|
||||||
u URI
|
u Location
|
||||||
}{
|
}{
|
||||||
{"local:/srv/repo", URI{Scheme: "local", Config: "/srv/repo"}},
|
{"local:/srv/repo", Location{Scheme: "local", Config: "/srv/repo"}},
|
||||||
{"local:dir1/dir2", URI{Scheme: "local", Config: "dir1/dir2"}},
|
{"local:dir1/dir2", Location{Scheme: "local", Config: "dir1/dir2"}},
|
||||||
{"local:dir1/dir2", URI{Scheme: "local", Config: "dir1/dir2"}},
|
{"local:dir1/dir2", Location{Scheme: "local", Config: "dir1/dir2"}},
|
||||||
{"dir1/dir2", URI{Scheme: "local", Config: "dir1/dir2"}},
|
{"dir1/dir2", Location{Scheme: "local", Config: "dir1/dir2"}},
|
||||||
{"local:../dir1/dir2", URI{Scheme: "local", Config: "../dir1/dir2"}},
|
{"local:../dir1/dir2", Location{Scheme: "local", Config: "../dir1/dir2"}},
|
||||||
{"/dir1/dir2", URI{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{
|
Config: sftp.Config{
|
||||||
User: "user",
|
User: "user",
|
||||||
Host: "host",
|
Host: "host",
|
||||||
Dir: "/srv/repo",
|
Dir: "/srv/repo",
|
||||||
}}},
|
}}},
|
||||||
{"sftp:host:/srv/repo", URI{Scheme: "sftp",
|
{"sftp:host:/srv/repo", Location{Scheme: "sftp",
|
||||||
Config: sftp.Config{
|
Config: sftp.Config{
|
||||||
User: "",
|
User: "",
|
||||||
Host: "host",
|
Host: "host",
|
||||||
Dir: "/srv/repo",
|
Dir: "/srv/repo",
|
||||||
}}},
|
}}},
|
||||||
{"sftp://user@host/srv/repo", URI{Scheme: "sftp",
|
{"sftp://user@host/srv/repo", Location{Scheme: "sftp",
|
||||||
Config: sftp.Config{
|
Config: sftp.Config{
|
||||||
User: "user",
|
User: "user",
|
||||||
Host: "host",
|
Host: "host",
|
||||||
Dir: "srv/repo",
|
Dir: "srv/repo",
|
||||||
}}},
|
}}},
|
||||||
{"sftp://user@host//srv/repo", URI{Scheme: "sftp",
|
{"sftp://user@host//srv/repo", Location{Scheme: "sftp",
|
||||||
Config: sftp.Config{
|
Config: sftp.Config{
|
||||||
User: "user",
|
User: "user",
|
||||||
Host: "host",
|
Host: "host",
|
||||||
Dir: "/srv/repo",
|
Dir: "/srv/repo",
|
||||||
}}},
|
}}},
|
||||||
|
|
||||||
{"s3://eu-central-1/bucketname", URI{Scheme: "s3",
|
{"s3://eu-central-1/bucketname", Location{Scheme: "s3",
|
||||||
Config: s3.Config{
|
Config: s3.Config{
|
||||||
Host: "eu-central-1",
|
Host: "eu-central-1",
|
||||||
Bucket: "bucketname",
|
Bucket: "bucketname",
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
{"s3://hostname.foo/bucketname", URI{Scheme: "s3",
|
{"s3://hostname.foo/bucketname", Location{Scheme: "s3",
|
||||||
Config: s3.Config{
|
Config: s3.Config{
|
||||||
Host: "hostname.foo",
|
Host: "hostname.foo",
|
||||||
Bucket: "bucketname",
|
Bucket: "bucketname",
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
{"s3:hostname.foo:repo", URI{Scheme: "s3",
|
{"s3:hostname.foo:repo", Location{Scheme: "s3",
|
||||||
Config: s3.Config{
|
Config: s3.Config{
|
||||||
Host: "hostname.foo",
|
Host: "hostname.foo",
|
||||||
Bucket: "repo",
|
Bucket: "repo",
|
||||||
@ -64,9 +64,9 @@ var parseTests = []struct {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseURI(t *testing.T) {
|
func TestParseLocation(t *testing.T) {
|
||||||
for i, test := range parseTests {
|
for i, test := range parseTests {
|
||||||
u, err := ParseURI(test.s)
|
u, err := ParseLocation(test.s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
continue
|
continue
|
Loading…
Reference in New Issue
Block a user