2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-23 11:28:54 +00:00

sftp: Add layout tests

This commit is contained in:
Alexander Neumann 2017-04-10 22:35:03 +02:00
parent 783fd73ea1
commit e8780f1ec6
2 changed files with 54 additions and 5 deletions

View File

@ -0,0 +1,46 @@
package sftp_test
import (
"fmt"
"path/filepath"
"restic/backend/sftp"
. "restic/test"
"testing"
)
func TestLayout(t *testing.T) {
path, cleanup := TempDir(t)
defer cleanup()
var tests = []struct {
filename string
layout string
failureExpected bool
}{
{"repo-layout-local.tar.gz", "", false},
{"repo-layout-cloud.tar.gz", "", false},
{"repo-layout-s3-old.tar.gz", "", false},
}
for _, test := range tests {
t.Run(test.filename, func(t *testing.T) {
SetupTarTestFixture(t, path, filepath.Join("..", "testdata", test.filename))
repo := filepath.Join(path, "repo")
be, err := sftp.Open(sftp.Config{
Command: fmt.Sprintf("%q -e", sftpserver),
Path: repo,
Layout: test.layout,
})
if err != nil {
t.Fatal(err)
}
if be == nil {
t.Fatalf("Open() returned nil but no error")
}
RemoveAll(t, filepath.Join(path, "repo"))
})
}
}

View File

@ -34,18 +34,21 @@ func createTempdir() error {
return nil return nil
} }
func init() { func findSFTPServerBinary() string {
sftpserver := ""
for _, dir := range strings.Split(TestSFTPPath, ":") { for _, dir := range strings.Split(TestSFTPPath, ":") {
testpath := filepath.Join(dir, "sftp-server") testpath := filepath.Join(dir, "sftp-server")
_, err := os.Stat(testpath) _, err := os.Stat(testpath)
if !os.IsNotExist(errors.Cause(err)) { if !os.IsNotExist(errors.Cause(err)) {
sftpserver = testpath return testpath
break
} }
} }
return ""
}
var sftpserver = findSFTPServerBinary()
func init() {
if sftpserver == "" { if sftpserver == "" {
SkipMessage = "sftp server binary not found, skipping tests" SkipMessage = "sftp server binary not found, skipping tests"
return return