2
2
mirror of https://github.com/octoleo/restic.git synced 2024-12-30 21:41:54 +00:00
restic/backend/sftp_test.go

66 lines
1.1 KiB
Go
Raw Normal View History

package backend_test
import (
"io/ioutil"
"os"
2015-06-13 11:16:43 +00:00
"path/filepath"
"strings"
"testing"
2015-03-28 10:50:23 +00:00
"github.com/restic/restic/backend/sftp"
2015-04-09 19:15:48 +00:00
. "github.com/restic/restic/test"
)
2015-03-28 10:50:23 +00:00
func setupSFTPBackend(t *testing.T) *sftp.SFTP {
2015-06-13 11:16:43 +00:00
sftpserver := ""
for _, dir := range strings.Split(TestSFTPPath, ":") {
testpath := filepath.Join(dir, "sftp-server")
fd, err := os.Open(testpath)
fd.Close()
if !os.IsNotExist(err) {
sftpserver = testpath
break
}
}
if sftpserver == "" {
return nil
}
tempdir, err := ioutil.TempDir("", "restic-test-")
2015-04-09 19:15:48 +00:00
OK(t, err)
2015-06-13 11:16:43 +00:00
b, err := sftp.Create(tempdir, sftpserver)
2015-04-09 19:15:48 +00:00
OK(t, err)
t.Logf("created sftp backend locally at %s", tempdir)
return b
}
2015-03-28 10:50:23 +00:00
func teardownSFTPBackend(t *testing.T, b *sftp.SFTP) {
2015-06-13 10:35:19 +00:00
if !TestCleanup {
t.Logf("leaving backend at %s\n", b.Location())
return
}
err := os.RemoveAll(b.Location())
2015-04-09 19:15:48 +00:00
OK(t, err)
}
func TestSFTPBackend(t *testing.T) {
2015-06-13 10:35:19 +00:00
if !RunIntegrationTest {
2015-06-13 11:16:43 +00:00
t.Skip("integration tests disabled")
}
s := setupSFTPBackend(t)
2015-06-13 11:16:43 +00:00
if s == nil {
t.Skip("unable to find sftp-server binary")
return
}
defer teardownSFTPBackend(t, s)
testBackend(s, t)
}