2022-10-15 14:23:39 +00:00
|
|
|
package layout
|
2017-03-26 19:52:49 +00:00
|
|
|
|
|
|
|
import (
|
2020-09-19 20:01:32 +00:00
|
|
|
"context"
|
2017-03-26 19:52:49 +00:00
|
|
|
"fmt"
|
2017-04-11 19:28:31 +00:00
|
|
|
"path"
|
2017-03-26 19:52:49 +00:00
|
|
|
"path/filepath"
|
|
|
|
"reflect"
|
|
|
|
"sort"
|
|
|
|
"testing"
|
2017-07-23 12:21:03 +00:00
|
|
|
|
2017-07-24 15:42:25 +00:00
|
|
|
"github.com/restic/restic/internal/restic"
|
2017-10-02 13:06:39 +00:00
|
|
|
rtest "github.com/restic/restic/internal/test"
|
2017-03-26 19:52:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestDefaultLayout(t *testing.T) {
|
2017-10-02 13:06:39 +00:00
|
|
|
tempdir, cleanup := rtest.TempDir(t)
|
2017-03-26 19:52:49 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
var tests = []struct {
|
2017-05-28 09:06:48 +00:00
|
|
|
path string
|
|
|
|
join func(...string) string
|
2017-03-26 19:52:49 +00:00
|
|
|
restic.Handle
|
|
|
|
filename string
|
|
|
|
}{
|
|
|
|
{
|
2017-05-28 09:06:48 +00:00
|
|
|
tempdir,
|
|
|
|
filepath.Join,
|
2020-08-16 09:16:38 +00:00
|
|
|
restic.Handle{Type: restic.PackFile, Name: "0123456"},
|
2017-05-28 09:06:48 +00:00
|
|
|
filepath.Join(tempdir, "data", "01", "0123456"),
|
2017-03-26 19:52:49 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-28 09:06:48 +00:00
|
|
|
tempdir,
|
|
|
|
filepath.Join,
|
2017-03-26 19:52:49 +00:00
|
|
|
restic.Handle{Type: restic.ConfigFile, Name: "CFG"},
|
2017-05-28 09:06:48 +00:00
|
|
|
filepath.Join(tempdir, "config"),
|
2017-03-26 19:52:49 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-28 09:06:48 +00:00
|
|
|
tempdir,
|
|
|
|
filepath.Join,
|
2017-03-26 19:52:49 +00:00
|
|
|
restic.Handle{Type: restic.SnapshotFile, Name: "123456"},
|
2017-05-28 09:06:48 +00:00
|
|
|
filepath.Join(tempdir, "snapshots", "123456"),
|
2017-03-26 19:52:49 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-28 09:06:48 +00:00
|
|
|
tempdir,
|
|
|
|
filepath.Join,
|
2017-03-26 19:52:49 +00:00
|
|
|
restic.Handle{Type: restic.IndexFile, Name: "123456"},
|
2017-05-28 09:06:48 +00:00
|
|
|
filepath.Join(tempdir, "index", "123456"),
|
2017-03-26 19:52:49 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-28 09:06:48 +00:00
|
|
|
tempdir,
|
|
|
|
filepath.Join,
|
2017-03-26 19:52:49 +00:00
|
|
|
restic.Handle{Type: restic.LockFile, Name: "123456"},
|
2017-05-28 09:06:48 +00:00
|
|
|
filepath.Join(tempdir, "locks", "123456"),
|
2017-03-26 19:52:49 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-28 09:06:48 +00:00
|
|
|
tempdir,
|
|
|
|
filepath.Join,
|
2017-03-26 19:52:49 +00:00
|
|
|
restic.Handle{Type: restic.KeyFile, Name: "123456"},
|
2017-05-28 09:06:48 +00:00
|
|
|
filepath.Join(tempdir, "keys", "123456"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
path.Join,
|
2020-08-16 09:16:38 +00:00
|
|
|
restic.Handle{Type: restic.PackFile, Name: "0123456"},
|
2017-05-28 09:06:48 +00:00
|
|
|
"data/01/0123456",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
path.Join,
|
|
|
|
restic.Handle{Type: restic.ConfigFile, Name: "CFG"},
|
|
|
|
"config",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
path.Join,
|
|
|
|
restic.Handle{Type: restic.SnapshotFile, Name: "123456"},
|
|
|
|
"snapshots/123456",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
path.Join,
|
|
|
|
restic.Handle{Type: restic.IndexFile, Name: "123456"},
|
|
|
|
"index/123456",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
path.Join,
|
|
|
|
restic.Handle{Type: restic.LockFile, Name: "123456"},
|
|
|
|
"locks/123456",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"",
|
|
|
|
path.Join,
|
|
|
|
restic.Handle{Type: restic.KeyFile, Name: "123456"},
|
|
|
|
"keys/123456",
|
2017-03-26 19:52:49 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Paths", func(t *testing.T) {
|
2017-05-28 09:06:48 +00:00
|
|
|
l := &DefaultLayout{
|
|
|
|
Path: tempdir,
|
|
|
|
Join: filepath.Join,
|
|
|
|
}
|
|
|
|
|
2017-03-26 19:52:49 +00:00
|
|
|
dirs := l.Paths()
|
|
|
|
|
|
|
|
want := []string{
|
2017-05-28 09:06:48 +00:00
|
|
|
filepath.Join(tempdir, "data"),
|
|
|
|
filepath.Join(tempdir, "snapshots"),
|
|
|
|
filepath.Join(tempdir, "index"),
|
|
|
|
filepath.Join(tempdir, "locks"),
|
|
|
|
filepath.Join(tempdir, "keys"),
|
2017-03-26 19:52:49 +00:00
|
|
|
}
|
|
|
|
|
2017-07-02 13:29:54 +00:00
|
|
|
for i := 0; i < 256; i++ {
|
|
|
|
want = append(want, filepath.Join(tempdir, "data", fmt.Sprintf("%02x", i)))
|
|
|
|
}
|
|
|
|
|
2019-06-30 20:20:32 +00:00
|
|
|
sort.Strings(want)
|
|
|
|
sort.Strings(dirs)
|
2017-03-26 19:52:49 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(dirs, want) {
|
2017-03-26 20:20:10 +00:00
|
|
|
t.Fatalf("wrong paths returned, want:\n %v\ngot:\n %v", want, dirs)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(fmt.Sprintf("%v/%v", test.Type, test.Handle.Name), func(t *testing.T) {
|
2017-05-28 09:06:48 +00:00
|
|
|
l := &DefaultLayout{
|
|
|
|
Path: test.path,
|
|
|
|
Join: test.join,
|
|
|
|
}
|
|
|
|
|
2017-03-26 20:20:10 +00:00
|
|
|
filename := l.Filename(test.Handle)
|
|
|
|
if filename != test.filename {
|
|
|
|
t.Fatalf("wrong filename, want %v, got %v", test.filename, filename)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 20:01:49 +00:00
|
|
|
func TestRESTLayout(t *testing.T) {
|
2017-10-02 13:06:39 +00:00
|
|
|
path, cleanup := rtest.TempDir(t)
|
2017-03-26 20:20:10 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
var tests = []struct {
|
|
|
|
restic.Handle
|
|
|
|
filename string
|
|
|
|
}{
|
|
|
|
{
|
2020-08-16 09:16:38 +00:00
|
|
|
restic.Handle{Type: restic.PackFile, Name: "0123456"},
|
2017-03-26 20:20:10 +00:00
|
|
|
filepath.Join(path, "data", "0123456"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.ConfigFile, Name: "CFG"},
|
|
|
|
filepath.Join(path, "config"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.SnapshotFile, Name: "123456"},
|
|
|
|
filepath.Join(path, "snapshots", "123456"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.IndexFile, Name: "123456"},
|
|
|
|
filepath.Join(path, "index", "123456"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.LockFile, Name: "123456"},
|
|
|
|
filepath.Join(path, "locks", "123456"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.KeyFile, Name: "123456"},
|
|
|
|
filepath.Join(path, "keys", "123456"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-15 20:01:49 +00:00
|
|
|
l := &RESTLayout{
|
2017-03-26 20:20:10 +00:00
|
|
|
Path: path,
|
|
|
|
Join: filepath.Join,
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Paths", func(t *testing.T) {
|
|
|
|
dirs := l.Paths()
|
|
|
|
|
|
|
|
want := []string{
|
|
|
|
filepath.Join(path, "data"),
|
|
|
|
filepath.Join(path, "snapshots"),
|
|
|
|
filepath.Join(path, "index"),
|
|
|
|
filepath.Join(path, "locks"),
|
|
|
|
filepath.Join(path, "keys"),
|
|
|
|
}
|
|
|
|
|
2019-06-30 20:20:32 +00:00
|
|
|
sort.Strings(want)
|
|
|
|
sort.Strings(dirs)
|
2017-03-26 20:20:10 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(dirs, want) {
|
|
|
|
t.Fatalf("wrong paths returned, want:\n %v\ngot:\n %v", want, dirs)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(fmt.Sprintf("%v/%v", test.Type, test.Handle.Name), func(t *testing.T) {
|
|
|
|
filename := l.Filename(test.Handle)
|
|
|
|
if filename != test.filename {
|
|
|
|
t.Fatalf("wrong filename, want %v, got %v", test.filename, filename)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 20:01:49 +00:00
|
|
|
func TestRESTLayoutURLs(t *testing.T) {
|
2017-04-11 19:28:31 +00:00
|
|
|
var tests = []struct {
|
2017-04-11 20:04:04 +00:00
|
|
|
l Layout
|
|
|
|
h restic.Handle
|
|
|
|
fn string
|
|
|
|
dir string
|
2017-04-11 19:28:31 +00:00
|
|
|
}{
|
|
|
|
{
|
2017-05-15 20:01:49 +00:00
|
|
|
&RESTLayout{URL: "https://hostname.foo", Path: "", Join: path.Join},
|
2020-08-16 09:16:38 +00:00
|
|
|
restic.Handle{Type: restic.PackFile, Name: "foobar"},
|
2017-04-11 19:28:31 +00:00
|
|
|
"https://hostname.foo/data/foobar",
|
2017-04-11 20:04:04 +00:00
|
|
|
"https://hostname.foo/data/",
|
2017-04-11 19:28:31 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-15 20:01:49 +00:00
|
|
|
&RESTLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join},
|
2017-04-11 19:28:31 +00:00
|
|
|
restic.Handle{Type: restic.LockFile, Name: "foobar"},
|
|
|
|
"https://hostname.foo:1234/prefix/repo/locks/foobar",
|
2017-04-11 20:04:04 +00:00
|
|
|
"https://hostname.foo:1234/prefix/repo/locks/",
|
2017-04-11 19:28:31 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-15 20:01:49 +00:00
|
|
|
&RESTLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join},
|
2017-04-11 19:28:31 +00:00
|
|
|
restic.Handle{Type: restic.ConfigFile, Name: "foobar"},
|
|
|
|
"https://hostname.foo:1234/prefix/repo/config",
|
2017-04-11 20:04:04 +00:00
|
|
|
"https://hostname.foo:1234/prefix/repo/",
|
2017-04-11 19:28:31 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-15 19:58:03 +00:00
|
|
|
&S3LegacyLayout{URL: "https://hostname.foo", Path: "/", Join: path.Join},
|
2020-08-16 09:16:38 +00:00
|
|
|
restic.Handle{Type: restic.PackFile, Name: "foobar"},
|
2017-04-11 19:28:31 +00:00
|
|
|
"https://hostname.foo/data/foobar",
|
2017-04-11 20:04:04 +00:00
|
|
|
"https://hostname.foo/data/",
|
2017-04-11 19:28:31 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-15 19:58:03 +00:00
|
|
|
&S3LegacyLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "", Join: path.Join},
|
2017-04-11 19:28:31 +00:00
|
|
|
restic.Handle{Type: restic.LockFile, Name: "foobar"},
|
|
|
|
"https://hostname.foo:1234/prefix/repo/lock/foobar",
|
2017-04-11 20:04:04 +00:00
|
|
|
"https://hostname.foo:1234/prefix/repo/lock/",
|
2017-04-11 19:28:31 +00:00
|
|
|
},
|
|
|
|
{
|
2017-05-15 19:58:03 +00:00
|
|
|
&S3LegacyLayout{URL: "https://hostname.foo:1234/prefix/repo", Path: "/", Join: path.Join},
|
2017-04-11 19:28:31 +00:00
|
|
|
restic.Handle{Type: restic.ConfigFile, Name: "foobar"},
|
|
|
|
"https://hostname.foo:1234/prefix/repo/config",
|
2017-04-11 20:04:04 +00:00
|
|
|
"https://hostname.foo:1234/prefix/repo/",
|
2017-04-11 19:28:31 +00:00
|
|
|
},
|
2017-04-17 18:06:06 +00:00
|
|
|
{
|
2017-05-15 19:58:03 +00:00
|
|
|
&S3LegacyLayout{URL: "", Path: "", Join: path.Join},
|
2020-08-16 09:16:38 +00:00
|
|
|
restic.Handle{Type: restic.PackFile, Name: "foobar"},
|
2017-04-17 18:06:06 +00:00
|
|
|
"data/foobar",
|
|
|
|
"data/",
|
|
|
|
},
|
|
|
|
{
|
2017-05-15 19:58:03 +00:00
|
|
|
&S3LegacyLayout{URL: "", Path: "", Join: path.Join},
|
2017-04-17 18:06:06 +00:00
|
|
|
restic.Handle{Type: restic.LockFile, Name: "foobar"},
|
|
|
|
"lock/foobar",
|
|
|
|
"lock/",
|
|
|
|
},
|
|
|
|
{
|
2017-05-15 19:58:03 +00:00
|
|
|
&S3LegacyLayout{URL: "", Path: "/", Join: path.Join},
|
2017-04-17 18:06:06 +00:00
|
|
|
restic.Handle{Type: restic.ConfigFile, Name: "foobar"},
|
|
|
|
"/config",
|
|
|
|
"/",
|
|
|
|
},
|
2017-04-11 19:28:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
2017-04-11 20:04:04 +00:00
|
|
|
t.Run(fmt.Sprintf("%T", test.l), func(t *testing.T) {
|
|
|
|
fn := test.l.Filename(test.h)
|
|
|
|
if fn != test.fn {
|
|
|
|
t.Fatalf("wrong filename, want %v, got %v", test.fn, fn)
|
|
|
|
}
|
|
|
|
|
|
|
|
dir := test.l.Dirname(test.h)
|
|
|
|
if dir != test.dir {
|
|
|
|
t.Fatalf("wrong dirname, want %v, got %v", test.dir, dir)
|
2017-04-11 19:28:31 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 19:58:03 +00:00
|
|
|
func TestS3LegacyLayout(t *testing.T) {
|
2017-10-02 13:06:39 +00:00
|
|
|
path, cleanup := rtest.TempDir(t)
|
2017-03-26 20:20:10 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
var tests = []struct {
|
|
|
|
restic.Handle
|
|
|
|
filename string
|
|
|
|
}{
|
|
|
|
{
|
2020-08-16 09:16:38 +00:00
|
|
|
restic.Handle{Type: restic.PackFile, Name: "0123456"},
|
2017-03-26 20:20:10 +00:00
|
|
|
filepath.Join(path, "data", "0123456"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.ConfigFile, Name: "CFG"},
|
|
|
|
filepath.Join(path, "config"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.SnapshotFile, Name: "123456"},
|
|
|
|
filepath.Join(path, "snapshot", "123456"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.IndexFile, Name: "123456"},
|
|
|
|
filepath.Join(path, "index", "123456"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.LockFile, Name: "123456"},
|
|
|
|
filepath.Join(path, "lock", "123456"),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
restic.Handle{Type: restic.KeyFile, Name: "123456"},
|
|
|
|
filepath.Join(path, "key", "123456"),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-05-15 19:58:03 +00:00
|
|
|
l := &S3LegacyLayout{
|
2017-03-26 20:20:10 +00:00
|
|
|
Path: path,
|
|
|
|
Join: filepath.Join,
|
|
|
|
}
|
|
|
|
|
|
|
|
t.Run("Paths", func(t *testing.T) {
|
|
|
|
dirs := l.Paths()
|
|
|
|
|
|
|
|
want := []string{
|
|
|
|
filepath.Join(path, "data"),
|
|
|
|
filepath.Join(path, "snapshot"),
|
|
|
|
filepath.Join(path, "index"),
|
|
|
|
filepath.Join(path, "lock"),
|
|
|
|
filepath.Join(path, "key"),
|
|
|
|
}
|
|
|
|
|
2019-06-30 20:20:32 +00:00
|
|
|
sort.Strings(want)
|
|
|
|
sort.Strings(dirs)
|
2017-03-26 20:20:10 +00:00
|
|
|
|
|
|
|
if !reflect.DeepEqual(dirs, want) {
|
|
|
|
t.Fatalf("wrong paths returned, want:\n %v\ngot:\n %v", want, dirs)
|
2017-03-26 19:52:49 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(fmt.Sprintf("%v/%v", test.Type, test.Handle.Name), func(t *testing.T) {
|
|
|
|
filename := l.Filename(test.Handle)
|
|
|
|
if filename != test.filename {
|
|
|
|
t.Fatalf("wrong filename, want %v, got %v", test.filename, filename)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2017-04-02 15:25:22 +00:00
|
|
|
|
|
|
|
func TestDetectLayout(t *testing.T) {
|
2017-10-02 13:06:39 +00:00
|
|
|
path, cleanup := rtest.TempDir(t)
|
2017-04-02 15:25:22 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
var tests = []struct {
|
|
|
|
filename string
|
|
|
|
want string
|
|
|
|
}{
|
2022-10-15 14:23:39 +00:00
|
|
|
{"repo-layout-default.tar.gz", "*layout.DefaultLayout"},
|
|
|
|
{"repo-layout-s3legacy.tar.gz", "*layout.S3LegacyLayout"},
|
2017-04-02 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var fs = &LocalFilesystem{}
|
|
|
|
for _, test := range tests {
|
2017-04-02 15:57:28 +00:00
|
|
|
for _, fs := range []Filesystem{fs, nil} {
|
|
|
|
t.Run(fmt.Sprintf("%v/fs-%T", test.filename, fs), func(t *testing.T) {
|
2022-10-15 14:23:39 +00:00
|
|
|
rtest.SetupTarTestFixture(t, path, filepath.Join("../testdata", test.filename))
|
2017-04-02 15:57:28 +00:00
|
|
|
|
2020-09-19 20:01:32 +00:00
|
|
|
layout, err := DetectLayout(context.TODO(), fs, filepath.Join(path, "repo"))
|
2017-04-02 15:57:28 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if layout == nil {
|
|
|
|
t.Fatal("wanted some layout, but detect returned nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
layoutName := fmt.Sprintf("%T", layout)
|
|
|
|
if layoutName != test.want {
|
|
|
|
t.Fatalf("want layout %v, got %v", test.want, layoutName)
|
|
|
|
}
|
|
|
|
|
2017-10-02 13:06:39 +00:00
|
|
|
rtest.RemoveAll(t, filepath.Join(path, "repo"))
|
2017-04-02 15:57:28 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseLayout(t *testing.T) {
|
2017-10-02 13:06:39 +00:00
|
|
|
path, cleanup := rtest.TempDir(t)
|
2017-04-02 15:57:28 +00:00
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
var tests = []struct {
|
2017-04-02 17:53:55 +00:00
|
|
|
layoutName string
|
|
|
|
defaultLayoutName string
|
|
|
|
want string
|
2017-04-02 15:57:28 +00:00
|
|
|
}{
|
2022-10-15 14:23:39 +00:00
|
|
|
{"default", "", "*layout.DefaultLayout"},
|
|
|
|
{"s3legacy", "", "*layout.S3LegacyLayout"},
|
|
|
|
{"", "", "*layout.DefaultLayout"},
|
2017-04-02 15:57:28 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 14:23:39 +00:00
|
|
|
rtest.SetupTarTestFixture(t, path, filepath.Join("..", "testdata", "repo-layout-default.tar.gz"))
|
2017-04-02 15:25:22 +00:00
|
|
|
|
2017-04-02 15:57:28 +00:00
|
|
|
for _, test := range tests {
|
|
|
|
t.Run(test.layoutName, func(t *testing.T) {
|
2020-09-19 20:01:32 +00:00
|
|
|
layout, err := ParseLayout(context.TODO(), &LocalFilesystem{}, test.layoutName, test.defaultLayoutName, filepath.Join(path, "repo"))
|
2017-04-02 15:25:22 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if layout == nil {
|
|
|
|
t.Fatal("wanted some layout, but detect returned nil")
|
|
|
|
}
|
|
|
|
|
2017-04-02 17:18:03 +00:00
|
|
|
// test that the functions work (and don't panic)
|
2020-08-16 09:16:38 +00:00
|
|
|
_ = layout.Dirname(restic.Handle{Type: restic.PackFile})
|
|
|
|
_ = layout.Filename(restic.Handle{Type: restic.PackFile, Name: "1234"})
|
2017-04-02 17:18:03 +00:00
|
|
|
_ = layout.Paths()
|
|
|
|
|
2017-04-02 15:25:22 +00:00
|
|
|
layoutName := fmt.Sprintf("%T", layout)
|
|
|
|
if layoutName != test.want {
|
|
|
|
t.Fatalf("want layout %v, got %v", test.want, layoutName)
|
|
|
|
}
|
2017-04-02 15:57:28 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseLayoutInvalid(t *testing.T) {
|
2017-10-02 13:06:39 +00:00
|
|
|
path, cleanup := rtest.TempDir(t)
|
2017-04-02 15:57:28 +00:00
|
|
|
defer cleanup()
|
2017-04-02 15:25:22 +00:00
|
|
|
|
2017-04-02 15:57:28 +00:00
|
|
|
var invalidNames = []string{
|
|
|
|
"foo", "bar", "local",
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range invalidNames {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
2020-09-19 20:01:32 +00:00
|
|
|
layout, err := ParseLayout(context.TODO(), nil, name, "", path)
|
2017-04-02 15:57:28 +00:00
|
|
|
if err == nil {
|
|
|
|
t.Fatalf("expected error not found for layout name %v, layout is %v", name, layout)
|
|
|
|
}
|
2017-04-02 15:25:22 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|