2015-02-11 19:17:55 +00:00
|
|
|
package backend_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"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-02-11 19:17:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var sftpPath = flag.String("test.sftppath", "", "sftp binary path (default: empty)")
|
|
|
|
|
2015-03-28 10:50:23 +00:00
|
|
|
func setupSFTPBackend(t *testing.T) *sftp.SFTP {
|
2015-02-11 19:17:55 +00:00
|
|
|
tempdir, err := ioutil.TempDir("", "restic-test-")
|
2015-04-09 19:15:48 +00:00
|
|
|
OK(t, err)
|
2015-02-11 19:17:55 +00:00
|
|
|
|
2015-03-28 10:50:23 +00:00
|
|
|
b, err := sftp.Create(tempdir, *sftpPath)
|
2015-04-09 19:15:48 +00:00
|
|
|
OK(t, err)
|
2015-02-11 19:17:55 +00:00
|
|
|
|
|
|
|
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-04-26 13:40:25 +00:00
|
|
|
if !*TestCleanup {
|
2015-02-11 19:17:55 +00:00
|
|
|
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)
|
2015-02-11 19:17:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestSFTPBackend(t *testing.T) {
|
2015-06-05 20:33:39 +00:00
|
|
|
if !*RunIntegrationTest {
|
|
|
|
t.Skip("integration tests disabled, use `-test.integration` to enable")
|
|
|
|
}
|
|
|
|
|
2015-02-11 19:17:55 +00:00
|
|
|
if *sftpPath == "" {
|
|
|
|
t.Skipf("sftppath not set, skipping TestSFTPBackend")
|
|
|
|
}
|
|
|
|
|
|
|
|
s := setupSFTPBackend(t)
|
|
|
|
defer teardownSFTPBackend(t, s)
|
|
|
|
|
|
|
|
testBackend(s, t)
|
|
|
|
}
|