forked from TrueCloudLab/restic
layout: Test DefaultLayout for empty path prefix
This commit is contained in:
parent
e046a2a6da
commit
1f5954e2c1
2 changed files with 73 additions and 18 deletions
|
@ -34,7 +34,7 @@ func (l *DefaultLayout) Dirname(h restic.Handle) string {
|
||||||
func (l *DefaultLayout) Filename(h restic.Handle) string {
|
func (l *DefaultLayout) Filename(h restic.Handle) string {
|
||||||
name := h.Name
|
name := h.Name
|
||||||
if h.Type == restic.ConfigFile {
|
if h.Type == restic.ConfigFile {
|
||||||
name = "config"
|
return l.Join(l.Path, "config")
|
||||||
}
|
}
|
||||||
|
|
||||||
return l.Join(l.Dirname(h), name)
|
return l.Join(l.Dirname(h), name)
|
||||||
|
|
|
@ -12,53 +12,103 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestDefaultLayout(t *testing.T) {
|
func TestDefaultLayout(t *testing.T) {
|
||||||
path, cleanup := TempDir(t)
|
tempdir, cleanup := TempDir(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
path string
|
||||||
|
join func(...string) string
|
||||||
restic.Handle
|
restic.Handle
|
||||||
filename string
|
filename string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
tempdir,
|
||||||
|
filepath.Join,
|
||||||
restic.Handle{Type: restic.DataFile, Name: "0123456"},
|
restic.Handle{Type: restic.DataFile, Name: "0123456"},
|
||||||
filepath.Join(path, "data", "01", "0123456"),
|
filepath.Join(tempdir, "data", "01", "0123456"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
tempdir,
|
||||||
|
filepath.Join,
|
||||||
restic.Handle{Type: restic.ConfigFile, Name: "CFG"},
|
restic.Handle{Type: restic.ConfigFile, Name: "CFG"},
|
||||||
filepath.Join(path, "config"),
|
filepath.Join(tempdir, "config"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
tempdir,
|
||||||
|
filepath.Join,
|
||||||
restic.Handle{Type: restic.SnapshotFile, Name: "123456"},
|
restic.Handle{Type: restic.SnapshotFile, Name: "123456"},
|
||||||
filepath.Join(path, "snapshots", "123456"),
|
filepath.Join(tempdir, "snapshots", "123456"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
tempdir,
|
||||||
|
filepath.Join,
|
||||||
restic.Handle{Type: restic.IndexFile, Name: "123456"},
|
restic.Handle{Type: restic.IndexFile, Name: "123456"},
|
||||||
filepath.Join(path, "index", "123456"),
|
filepath.Join(tempdir, "index", "123456"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
tempdir,
|
||||||
|
filepath.Join,
|
||||||
restic.Handle{Type: restic.LockFile, Name: "123456"},
|
restic.Handle{Type: restic.LockFile, Name: "123456"},
|
||||||
filepath.Join(path, "locks", "123456"),
|
filepath.Join(tempdir, "locks", "123456"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
tempdir,
|
||||||
|
filepath.Join,
|
||||||
restic.Handle{Type: restic.KeyFile, Name: "123456"},
|
restic.Handle{Type: restic.KeyFile, Name: "123456"},
|
||||||
filepath.Join(path, "keys", "123456"),
|
filepath.Join(tempdir, "keys", "123456"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"",
|
||||||
|
path.Join,
|
||||||
|
restic.Handle{Type: restic.DataFile, Name: "0123456"},
|
||||||
|
"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",
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
l := &DefaultLayout{
|
|
||||||
Path: path,
|
|
||||||
Join: filepath.Join,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("Paths", func(t *testing.T) {
|
t.Run("Paths", func(t *testing.T) {
|
||||||
|
l := &DefaultLayout{
|
||||||
|
Path: tempdir,
|
||||||
|
Join: filepath.Join,
|
||||||
|
}
|
||||||
|
|
||||||
dirs := l.Paths()
|
dirs := l.Paths()
|
||||||
|
|
||||||
want := []string{
|
want := []string{
|
||||||
filepath.Join(path, "data"),
|
filepath.Join(tempdir, "data"),
|
||||||
filepath.Join(path, "snapshots"),
|
filepath.Join(tempdir, "snapshots"),
|
||||||
filepath.Join(path, "index"),
|
filepath.Join(tempdir, "index"),
|
||||||
filepath.Join(path, "locks"),
|
filepath.Join(tempdir, "locks"),
|
||||||
filepath.Join(path, "keys"),
|
filepath.Join(tempdir, "keys"),
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(sort.StringSlice(want))
|
sort.Sort(sort.StringSlice(want))
|
||||||
|
@ -71,6 +121,11 @@ func TestDefaultLayout(t *testing.T) {
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
t.Run(fmt.Sprintf("%v/%v", test.Type, test.Handle.Name), func(t *testing.T) {
|
t.Run(fmt.Sprintf("%v/%v", test.Type, test.Handle.Name), func(t *testing.T) {
|
||||||
|
l := &DefaultLayout{
|
||||||
|
Path: test.path,
|
||||||
|
Join: test.join,
|
||||||
|
}
|
||||||
|
|
||||||
filename := l.Filename(test.Handle)
|
filename := l.Filename(test.Handle)
|
||||||
if filename != test.filename {
|
if filename != test.filename {
|
||||||
t.Fatalf("wrong filename, want %v, got %v", test.filename, filename)
|
t.Fatalf("wrong filename, want %v, got %v", test.filename, filename)
|
||||||
|
|
Loading…
Reference in a new issue