From 9861f3d43597cf65a83780208224d0170d74e077 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 25 Mar 2017 13:27:14 +0100 Subject: [PATCH] location: Reformat tests, use sub tests --- src/restic/location/location_test.go | 296 ++++++++++++++++----------- 1 file changed, 182 insertions(+), 114 deletions(-) diff --git a/src/restic/location/location_test.go b/src/restic/location/location_test.go index 2961ecd54..fe07ee506 100644 --- a/src/restic/location/location_test.go +++ b/src/restic/location/location_test.go @@ -24,136 +24,204 @@ var parseTests = []struct { s string u Location }{ - {"local:/srv/repo", Location{Scheme: "local", - Config: local.Config{ - Path: "/srv/repo", - }}}, - {"local: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", - }}}, - {"local:../dir1/dir2", Location{Scheme: "local", - Config: local.Config{ - Path: "../dir1/dir2", - }}}, - {"/dir1/dir2", Location{Scheme: "local", - Config: local.Config{ - Path: "/dir1/dir2", - }}}, + { + "local:/srv/repo", + Location{Scheme: "local", + Config: local.Config{ + Path: "/srv/repo", + }, + }, + }, + { + "local: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", + }, + }, + }, + { + "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{ - User: "user", - Host: "host", - Dir: "/srv/repo", - }}}, - {"sftp:host:/srv/repo", Location{Scheme: "sftp", - Config: sftp.Config{ - User: "", - Host: "host", - Dir: "/srv/repo", - }}}, - {"sftp://user@host/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", - }}}, + { + "sftp:user@host:/srv/repo", + Location{Scheme: "sftp", + Config: sftp.Config{ + User: "user", + Host: "host", + Dir: "/srv/repo", + }, + }, + }, + { + "sftp:host:/srv/repo", + Location{Scheme: "sftp", + Config: sftp.Config{ + User: "", + Host: "host", + Dir: "/srv/repo", + }, + }, + }, + { + "sftp://user@host/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{ - Endpoint: "eu-central-1", - Bucket: "bucketname", - Prefix: "restic", - }}, + { + "s3://eu-central-1/bucketname", + Location{Scheme: "s3", + Config: s3.Config{ + Endpoint: "eu-central-1", + Bucket: "bucketname", + Prefix: "restic", + }, + }, }, - {"s3://hostname.foo/bucketname", Location{Scheme: "s3", - Config: s3.Config{ - Endpoint: "hostname.foo", - Bucket: "bucketname", - Prefix: "restic", - }}, + { + "s3://hostname.foo/bucketname", + Location{Scheme: "s3", + Config: s3.Config{ + Endpoint: "hostname.foo", + Bucket: "bucketname", + Prefix: "restic", + }, + }, }, - {"s3://hostname.foo/bucketname/prefix/directory", Location{Scheme: "s3", - Config: s3.Config{ - Endpoint: "hostname.foo", - Bucket: "bucketname", - Prefix: "prefix/directory", - }}, + { + "s3://hostname.foo/bucketname/prefix/directory", + Location{Scheme: "s3", + Config: s3.Config{ + Endpoint: "hostname.foo", + Bucket: "bucketname", + Prefix: "prefix/directory", + }, + }, }, - {"s3:eu-central-1/repo", Location{Scheme: "s3", - Config: s3.Config{ - Endpoint: "eu-central-1", - Bucket: "repo", - Prefix: "restic", - }}, + { + "s3:eu-central-1/repo", + Location{Scheme: "s3", + Config: s3.Config{ + Endpoint: "eu-central-1", + Bucket: "repo", + Prefix: "restic", + }, + }, }, - {"s3:eu-central-1/repo/prefix/directory", Location{Scheme: "s3", - Config: s3.Config{ - Endpoint: "eu-central-1", - Bucket: "repo", - Prefix: "prefix/directory", - }}, + { + "s3:eu-central-1/repo/prefix/directory", + Location{Scheme: "s3", + Config: s3.Config{ + Endpoint: "eu-central-1", + Bucket: "repo", + Prefix: "prefix/directory", + }, + }, }, - {"s3:https://hostname.foo/repo", Location{Scheme: "s3", - Config: s3.Config{ - Endpoint: "hostname.foo", - Bucket: "repo", - Prefix: "restic", - }}, + { + "s3:https://hostname.foo/repo", + Location{Scheme: "s3", + Config: s3.Config{ + Endpoint: "hostname.foo", + Bucket: "repo", + Prefix: "restic", + }, + }, }, - {"s3:https://hostname.foo/repo/prefix/directory", Location{Scheme: "s3", - Config: s3.Config{ - Endpoint: "hostname.foo", - Bucket: "repo", - Prefix: "prefix/directory", - }}, + { + "s3:https://hostname.foo/repo/prefix/directory", + Location{Scheme: "s3", + Config: s3.Config{ + Endpoint: "hostname.foo", + Bucket: "repo", + Prefix: "prefix/directory", + }, + }, }, - {"s3:http://hostname.foo/repo", Location{Scheme: "s3", - Config: s3.Config{ - Endpoint: "hostname.foo", - Bucket: "repo", - Prefix: "restic", - UseHTTP: true, - }}, + { + "s3:http://hostname.foo/repo", + Location{Scheme: "s3", + Config: s3.Config{ + Endpoint: "hostname.foo", + Bucket: "repo", + Prefix: "restic", + UseHTTP: true, + }, + }, }, - {"rest:http://hostname.foo:1234/", Location{Scheme: "rest", - Config: rest.Config{ - URL: parseURL("http://hostname.foo:1234/"), - }}, + { + "rest:http://hostname.foo:1234/", + Location{Scheme: "rest", + Config: rest.Config{ + URL: parseURL("http://hostname.foo:1234/"), + }, + }, }, } func TestParse(t *testing.T) { for i, test := range parseTests { - u, err := Parse(test.s) - if err != nil { - t.Errorf("unexpected error: %v", err) - continue - } + t.Run(test.s, func(t *testing.T) { + u, err := Parse(test.s) + if err != nil { + t.Fatalf("unexpected error: %v", err) + } - 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 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) - } + 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) + } + }) } }