2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-18 02:55:18 +00:00
restic/backend/sftp_test.go

46 lines
827 B
Go
Raw Normal View History

package backend_test
import (
"flag"
"io/ioutil"
"os"
"testing"
2015-03-28 10:50:23 +00:00
"github.com/restic/restic/backend/sftp"
)
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 {
tempdir, err := ioutil.TempDir("", "restic-test-")
ok(t, err)
2015-03-28 10:50:23 +00:00
b, err := sftp.Create(tempdir, *sftpPath)
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) {
if !*testCleanup {
t.Logf("leaving backend at %s\n", b.Location())
return
}
err := os.RemoveAll(b.Location())
ok(t, err)
}
func TestSFTPBackend(t *testing.T) {
if *sftpPath == "" {
t.Skipf("sftppath not set, skipping TestSFTPBackend")
}
s := setupSFTPBackend(t)
defer teardownSFTPBackend(t, s)
testBackend(s, t)
}