location: Reformat tests, use sub tests

This commit is contained in:
Alexander Neumann 2017-03-25 13:27:14 +01:00
parent 482a6e9840
commit 9861f3d435

View file

@ -24,136 +24,204 @@ var parseTests = []struct {
s string s string
u Location u Location
}{ }{
{"local:/srv/repo", Location{Scheme: "local", {
Config: local.Config{ "local:/srv/repo",
Path: "/srv/repo", Location{Scheme: "local",
}}}, Config: local.Config{
{"local:dir1/dir2", Location{Scheme: "local", Path: "/srv/repo",
Config: local.Config{ },
Path: "dir1/dir2", },
}}}, },
{"local:dir1/dir2", Location{Scheme: "local", {
Config: local.Config{ "local:dir1/dir2",
Path: "dir1/dir2", Location{Scheme: "local",
}}}, Config: local.Config{
{"dir1/dir2", Location{Scheme: "local", Path: "dir1/dir2",
Config: local.Config{ },
Path: "dir1/dir2", },
}}}, },
{"local:../dir1/dir2", Location{Scheme: "local", {
Config: local.Config{ "local:dir1/dir2",
Path: "../dir1/dir2", Location{Scheme: "local",
}}}, Config: local.Config{
{"/dir1/dir2", Location{Scheme: "local", Path: "dir1/dir2",
Config: local.Config{ },
Path: "/dir1/dir2", },
}}}, },
{
"dir1/dir2",
Location{Scheme: "local",
Config: local.Config{
Path: "dir1/dir2",
},
},
},
{
"local:../dir1/dir2",
Location{Scheme: "local",
Config: local.Config{
Path: "../dir1/dir2",
},
},
},
{
"/dir1/dir2",
Location{Scheme: "local",
Config: local.Config{
Path: "/dir1/dir2",
},
},
},
{"sftp:user@host:/srv/repo", Location{Scheme: "sftp", {
Config: sftp.Config{ "sftp:user@host:/srv/repo",
User: "user", Location{Scheme: "sftp",
Host: "host", Config: sftp.Config{
Dir: "/srv/repo", User: "user",
}}}, Host: "host",
{"sftp:host:/srv/repo", Location{Scheme: "sftp", Dir: "/srv/repo",
Config: sftp.Config{ },
User: "", },
Host: "host", },
Dir: "/srv/repo", {
}}}, "sftp:host:/srv/repo",
{"sftp://user@host/srv/repo", Location{Scheme: "sftp", Location{Scheme: "sftp",
Config: sftp.Config{ Config: sftp.Config{
User: "user", User: "",
Host: "host", Host: "host",
Dir: "srv/repo", Dir: "/srv/repo",
}}}, },
{"sftp://user@host//srv/repo", Location{Scheme: "sftp", },
Config: sftp.Config{ },
User: "user", {
Host: "host", "sftp://user@host/srv/repo",
Dir: "/srv/repo", Location{Scheme: "sftp",
}}}, Config: sftp.Config{
User: "user",
Host: "host",
Dir: "srv/repo",
},
},
},
{
"sftp://user@host//srv/repo",
Location{Scheme: "sftp",
Config: sftp.Config{
User: "user",
Host: "host",
Dir: "/srv/repo",
},
},
},
{"s3://eu-central-1/bucketname", Location{Scheme: "s3", {
Config: s3.Config{ "s3://eu-central-1/bucketname",
Endpoint: "eu-central-1", Location{Scheme: "s3",
Bucket: "bucketname", Config: s3.Config{
Prefix: "restic", Endpoint: "eu-central-1",
}}, Bucket: "bucketname",
Prefix: "restic",
},
},
}, },
{"s3://hostname.foo/bucketname", Location{Scheme: "s3", {
Config: s3.Config{ "s3://hostname.foo/bucketname",
Endpoint: "hostname.foo", Location{Scheme: "s3",
Bucket: "bucketname", Config: s3.Config{
Prefix: "restic", Endpoint: "hostname.foo",
}}, Bucket: "bucketname",
Prefix: "restic",
},
},
}, },
{"s3://hostname.foo/bucketname/prefix/directory", Location{Scheme: "s3", {
Config: s3.Config{ "s3://hostname.foo/bucketname/prefix/directory",
Endpoint: "hostname.foo", Location{Scheme: "s3",
Bucket: "bucketname", Config: s3.Config{
Prefix: "prefix/directory", Endpoint: "hostname.foo",
}}, Bucket: "bucketname",
Prefix: "prefix/directory",
},
},
}, },
{"s3:eu-central-1/repo", Location{Scheme: "s3", {
Config: s3.Config{ "s3:eu-central-1/repo",
Endpoint: "eu-central-1", Location{Scheme: "s3",
Bucket: "repo", Config: s3.Config{
Prefix: "restic", Endpoint: "eu-central-1",
}}, Bucket: "repo",
Prefix: "restic",
},
},
}, },
{"s3:eu-central-1/repo/prefix/directory", Location{Scheme: "s3", {
Config: s3.Config{ "s3:eu-central-1/repo/prefix/directory",
Endpoint: "eu-central-1", Location{Scheme: "s3",
Bucket: "repo", Config: s3.Config{
Prefix: "prefix/directory", Endpoint: "eu-central-1",
}}, Bucket: "repo",
Prefix: "prefix/directory",
},
},
}, },
{"s3:https://hostname.foo/repo", Location{Scheme: "s3", {
Config: s3.Config{ "s3:https://hostname.foo/repo",
Endpoint: "hostname.foo", Location{Scheme: "s3",
Bucket: "repo", Config: s3.Config{
Prefix: "restic", Endpoint: "hostname.foo",
}}, Bucket: "repo",
Prefix: "restic",
},
},
}, },
{"s3:https://hostname.foo/repo/prefix/directory", Location{Scheme: "s3", {
Config: s3.Config{ "s3:https://hostname.foo/repo/prefix/directory",
Endpoint: "hostname.foo", Location{Scheme: "s3",
Bucket: "repo", Config: s3.Config{
Prefix: "prefix/directory", Endpoint: "hostname.foo",
}}, Bucket: "repo",
Prefix: "prefix/directory",
},
},
}, },
{"s3:http://hostname.foo/repo", Location{Scheme: "s3", {
Config: s3.Config{ "s3:http://hostname.foo/repo",
Endpoint: "hostname.foo", Location{Scheme: "s3",
Bucket: "repo", Config: s3.Config{
Prefix: "restic", Endpoint: "hostname.foo",
UseHTTP: true, Bucket: "repo",
}}, Prefix: "restic",
UseHTTP: true,
},
},
}, },
{"rest:http://hostname.foo:1234/", Location{Scheme: "rest", {
Config: rest.Config{ "rest:http://hostname.foo:1234/",
URL: parseURL("http://hostname.foo:1234/"), Location{Scheme: "rest",
}}, Config: rest.Config{
URL: parseURL("http://hostname.foo:1234/"),
},
},
}, },
} }
func TestParse(t *testing.T) { func TestParse(t *testing.T) {
for i, test := range parseTests { for i, test := range parseTests {
u, err := Parse(test.s) t.Run(test.s, func(t *testing.T) {
if err != nil { u, err := Parse(test.s)
t.Errorf("unexpected error: %v", err) if err != nil {
continue t.Fatalf("unexpected error: %v", err)
} }
if test.u.Scheme != u.Scheme { if test.u.Scheme != u.Scheme {
t.Errorf("test %d: scheme does not match, want %q, got %q", t.Errorf("test %d: scheme does not match, want %q, got %q",
i, test.u.Scheme, u.Scheme) i, test.u.Scheme, u.Scheme)
} }
if !reflect.DeepEqual(test.u.Config, u.Config) { if !reflect.DeepEqual(test.u.Config, u.Config) {
t.Errorf("test %d: cfg map does not match, want:\n %#v\ngot: \n %#v", t.Errorf("test %d: cfg map does not match, want:\n %#v\ngot: \n %#v",
i, test.u.Config, u.Config) i, test.u.Config, u.Config)
} }
})
} }
} }