1
0
mirror of https://github.com/restic/restic.git synced 2025-08-16 11:57:31 +00:00
Files
.github
changelog
cmd
contrib
doc
docker
helpers
internal
archiver
backend
azure
b2
dryrun
gs
layout
limiter
local
location
logger
mem
mock
rclone
rest
retry
s3
sema
sftp
config.go
config_test.go
doc.go
layout_test.go
sftp.go
sftp_test.go
sshcmd_test.go
swift
test
testdata
doc.go
errdot_119.go
errdot_old.go
foreground.go
foreground_sysv.go
foreground_test.go
foreground_unix.go
foreground_windows.go
http_transport.go
paths.go
readerat.go
shell_split.go
shell_split_test.go
utils.go
utils_test.go
bloblru
cache
checker
crypto
debug
dump
errors
filter
fs
fuse
hashing
index
migrations
options
pack
repository
restic
restorer
selfupdate
test
textfile
ui
walker
.dockerignore
.gitattributes
.gitignore
.golangci.yml
CHANGELOG.md
CONTRIBUTING.md
GOVERNANCE.md
LICENSE
Makefile
README.md
VERSION
build.go
doc.go
go.mod
go.sum
restic/internal/backend/sftp/layout_test.go
2022-12-09 14:23:55 +01:00

91 lines
2.2 KiB
Go

package sftp_test
import (
"context"
"fmt"
"path/filepath"
"testing"
"github.com/restic/restic/internal/backend/sftp"
"github.com/restic/restic/internal/restic"
rtest "github.com/restic/restic/internal/test"
)
func TestLayout(t *testing.T) {
if sftpServer == "" {
t.Skip("sftp server binary not available")
}
path := rtest.TempDir(t)
var tests = []struct {
filename string
layout string
failureExpected bool
packfiles map[string]bool
}{
{"repo-layout-default.tar.gz", "", false, map[string]bool{
"aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false,
"fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false,
"c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false,
}},
{"repo-layout-s3legacy.tar.gz", "", false, map[string]bool{
"fc919a3b421850f6fa66ad22ebcf91e433e79ffef25becf8aef7c7b1eca91683": false,
"c089d62788da14f8b7cbf77188305c0874906f0b73d3fce5a8869050e8d0c0e1": false,
"aa464e9fd598fe4202492ee317ffa728e82fa83a1de1a61996e5bd2d6651646c": false,
}},
}
for _, test := range tests {
t.Run(test.filename, func(t *testing.T) {
rtest.SetupTarTestFixture(t, path, filepath.Join("..", "testdata", test.filename))
repo := filepath.Join(path, "repo")
be, err := sftp.Open(context.TODO(), sftp.Config{
Command: fmt.Sprintf("%q -e", sftpServer),
Path: repo,
Layout: test.layout,
Connections: 5,
})
if err != nil {
t.Fatal(err)
}
if be == nil {
t.Fatalf("Open() returned nil but no error")
}
packs := make(map[string]bool)
err = be.List(context.TODO(), restic.PackFile, func(fi restic.FileInfo) error {
packs[fi.Name] = false
return nil
})
rtest.OK(t, err)
if len(packs) == 0 {
t.Errorf("List() returned zero pack files")
}
for id := range test.packfiles {
if _, ok := packs[id]; !ok {
t.Errorf("packfile with id %v not found", id)
}
packs[id] = true
}
for id, v := range packs {
if !v {
t.Errorf("unexpected id %v found", id)
}
}
if err = be.Close(); err != nil {
t.Errorf("Close() returned error %v", err)
}
rtest.RemoveAll(t, filepath.Join(path, "repo"))
})
}
}