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,126 +24,193 @@ var parseTests = []struct {
s string s string
u Location u Location
}{ }{
{"local:/srv/repo", Location{Scheme: "local", {
"local:/srv/repo",
Location{Scheme: "local",
Config: local.Config{ Config: local.Config{
Path: "/srv/repo", Path: "/srv/repo",
}}}, },
{"local:dir1/dir2", Location{Scheme: "local", },
},
{
"local:dir1/dir2",
Location{Scheme: "local",
Config: local.Config{ Config: local.Config{
Path: "dir1/dir2", Path: "dir1/dir2",
}}}, },
{"local:dir1/dir2", Location{Scheme: "local", },
},
{
"local:dir1/dir2",
Location{Scheme: "local",
Config: local.Config{ Config: local.Config{
Path: "dir1/dir2", Path: "dir1/dir2",
}}}, },
{"dir1/dir2", Location{Scheme: "local", },
},
{
"dir1/dir2",
Location{Scheme: "local",
Config: local.Config{ Config: local.Config{
Path: "dir1/dir2", Path: "dir1/dir2",
}}}, },
{"local:../dir1/dir2", Location{Scheme: "local", },
},
{
"local:../dir1/dir2",
Location{Scheme: "local",
Config: local.Config{ Config: local.Config{
Path: "../dir1/dir2", Path: "../dir1/dir2",
}}}, },
{"/dir1/dir2", Location{Scheme: "local", },
},
{
"/dir1/dir2",
Location{Scheme: "local",
Config: local.Config{ Config: local.Config{
Path: "/dir1/dir2", Path: "/dir1/dir2",
}}}, },
},
},
{"sftp:user@host:/srv/repo", Location{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", Location{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", Location{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", Location{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", Location{Scheme: "s3", {
"s3://eu-central-1/bucketname",
Location{Scheme: "s3",
Config: s3.Config{ Config: s3.Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "bucketname", Bucket: "bucketname",
Prefix: "restic", Prefix: "restic",
}},
}, },
{"s3://hostname.foo/bucketname", Location{Scheme: "s3", },
},
{
"s3://hostname.foo/bucketname",
Location{Scheme: "s3",
Config: s3.Config{ Config: s3.Config{
Endpoint: "hostname.foo", Endpoint: "hostname.foo",
Bucket: "bucketname", Bucket: "bucketname",
Prefix: "restic", Prefix: "restic",
}},
}, },
{"s3://hostname.foo/bucketname/prefix/directory", Location{Scheme: "s3", },
},
{
"s3://hostname.foo/bucketname/prefix/directory",
Location{Scheme: "s3",
Config: s3.Config{ Config: s3.Config{
Endpoint: "hostname.foo", Endpoint: "hostname.foo",
Bucket: "bucketname", Bucket: "bucketname",
Prefix: "prefix/directory", Prefix: "prefix/directory",
}},
}, },
{"s3:eu-central-1/repo", Location{Scheme: "s3", },
},
{
"s3:eu-central-1/repo",
Location{Scheme: "s3",
Config: s3.Config{ Config: s3.Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "repo", Bucket: "repo",
Prefix: "restic", Prefix: "restic",
}},
}, },
{"s3:eu-central-1/repo/prefix/directory", Location{Scheme: "s3", },
},
{
"s3:eu-central-1/repo/prefix/directory",
Location{Scheme: "s3",
Config: s3.Config{ Config: s3.Config{
Endpoint: "eu-central-1", Endpoint: "eu-central-1",
Bucket: "repo", Bucket: "repo",
Prefix: "prefix/directory", Prefix: "prefix/directory",
}},
}, },
{"s3:https://hostname.foo/repo", Location{Scheme: "s3", },
},
{
"s3:https://hostname.foo/repo",
Location{Scheme: "s3",
Config: s3.Config{ Config: s3.Config{
Endpoint: "hostname.foo", Endpoint: "hostname.foo",
Bucket: "repo", Bucket: "repo",
Prefix: "restic", Prefix: "restic",
}},
}, },
{"s3:https://hostname.foo/repo/prefix/directory", Location{Scheme: "s3", },
},
{
"s3:https://hostname.foo/repo/prefix/directory",
Location{Scheme: "s3",
Config: s3.Config{ Config: s3.Config{
Endpoint: "hostname.foo", Endpoint: "hostname.foo",
Bucket: "repo", Bucket: "repo",
Prefix: "prefix/directory", Prefix: "prefix/directory",
}},
}, },
{"s3:http://hostname.foo/repo", Location{Scheme: "s3", },
},
{
"s3:http://hostname.foo/repo",
Location{Scheme: "s3",
Config: s3.Config{ Config: s3.Config{
Endpoint: "hostname.foo", Endpoint: "hostname.foo",
Bucket: "repo", Bucket: "repo",
Prefix: "restic", Prefix: "restic",
UseHTTP: true, UseHTTP: true,
}},
}, },
{"rest:http://hostname.foo:1234/", Location{Scheme: "rest", },
},
{
"rest:http://hostname.foo:1234/",
Location{Scheme: "rest",
Config: rest.Config{ Config: rest.Config{
URL: parseURL("http://hostname.foo:1234/"), 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 {
t.Run(test.s, func(t *testing.T) {
u, err := Parse(test.s) u, err := Parse(test.s)
if err != nil { if err != nil {
t.Errorf("unexpected error: %v", err) t.Fatalf("unexpected error: %v", err)
continue
} }
if test.u.Scheme != u.Scheme { if test.u.Scheme != u.Scheme {
@ -155,5 +222,6 @@ func TestParse(t *testing.T) {
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)
} }
})
} }
} }