2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-30 16:53:59 +00:00
restic/internal/backend/sftp/sftp_test.go

70 lines
1.4 KiB
Go
Raw Normal View History

2017-05-01 20:55:09 +00:00
package sftp_test
import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"
2017-07-23 12:21:03 +00:00
"github.com/restic/restic/internal/backend/sftp"
"github.com/restic/restic/internal/backend/test"
"github.com/restic/restic/internal/errors"
2017-10-02 13:06:39 +00:00
rtest "github.com/restic/restic/internal/test"
2017-05-01 20:55:09 +00:00
)
func findSFTPServerBinary() string {
2017-10-02 13:06:39 +00:00
for _, dir := range strings.Split(rtest.TestSFTPPath, ":") {
2017-05-01 20:55:09 +00:00
testpath := filepath.Join(dir, "sftp-server")
_, err := os.Stat(testpath)
if !errors.Is(err, os.ErrNotExist) {
2017-05-01 20:55:09 +00:00
return testpath
}
}
return ""
}
var sftpServer = findSFTPServerBinary()
func newTestSuite(t testing.TB) *test.Suite[sftp.Config] {
return &test.Suite[sftp.Config]{
2017-05-01 20:55:09 +00:00
// NewConfig returns a config for a new temporary backend that will be used in tests.
NewConfig: func() (*sftp.Config, error) {
dir := rtest.TempDir(t)
2017-05-01 20:55:09 +00:00
t.Logf("create new backend at %v", dir)
cfg := &sftp.Config{
Path: dir,
Command: fmt.Sprintf("%q -e", sftpServer),
Connections: 5,
2017-05-01 20:55:09 +00:00
}
return cfg, nil
},
Factory: sftp.NewFactory(),
2017-05-01 20:55:09 +00:00
}
2017-05-13 19:59:00 +00:00
}
func TestBackendSFTP(t *testing.T) {
defer func() {
if t.Skipped() {
2017-10-02 13:06:39 +00:00
rtest.SkipDisallowed(t, "restic/backend/sftp.TestBackendSFTP")
2017-05-13 19:59:00 +00:00
}
}()
if sftpServer == "" {
t.Skip("sftp server binary not found")
}
newTestSuite(t).RunTests(t)
}
func BenchmarkBackendSFTP(t *testing.B) {
if sftpServer == "" {
t.Skip("sftp server binary not found")
}
2017-05-01 20:55:09 +00:00
2017-05-13 19:59:00 +00:00
newTestSuite(t).RunBenchmarks(t)
2017-05-01 20:55:09 +00:00
}