Remove more flags from tests

This commit is contained in:
Alexander Neumann 2015-06-13 13:16:43 +02:00
parent 0ad08b2f70
commit 9853fbcf48
3 changed files with 27 additions and 10 deletions

View file

@ -1,22 +1,37 @@
package backend_test package backend_test
import ( import (
"flag"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"strings"
"testing" "testing"
"github.com/restic/restic/backend/sftp" "github.com/restic/restic/backend/sftp"
. "github.com/restic/restic/test" . "github.com/restic/restic/test"
) )
var sftpPath = flag.String("test.sftppath", "", "sftp binary path (default: empty)")
func setupSFTPBackend(t *testing.T) *sftp.SFTP { func setupSFTPBackend(t *testing.T) *sftp.SFTP {
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-") tempdir, err := ioutil.TempDir("", "restic-test-")
OK(t, err) OK(t, err)
b, err := sftp.Create(tempdir, *sftpPath) b, err := sftp.Create(tempdir, sftpserver)
OK(t, err) OK(t, err)
t.Logf("created sftp backend locally at %s", tempdir) t.Logf("created sftp backend locally at %s", tempdir)
@ -36,14 +51,14 @@ func teardownSFTPBackend(t *testing.T, b *sftp.SFTP) {
func TestSFTPBackend(t *testing.T) { func TestSFTPBackend(t *testing.T) {
if !RunIntegrationTest { if !RunIntegrationTest {
t.Skip("integration tests disabled, use `-test.integration` to enable") t.Skip("integration tests disabled")
}
if *sftpPath == "" {
t.Skipf("sftppath not set, skipping TestSFTPBackend")
} }
s := setupSFTPBackend(t) s := setupSFTPBackend(t)
if s == nil {
t.Skip("unable to find sftp-server binary")
return
}
defer teardownSFTPBackend(t, s) defer teardownSFTPBackend(t, s)
testBackend(s, t) testBackend(s, t)

View file

@ -114,7 +114,7 @@ func cmdFsck(t testing.TB) {
func TestBackup(t *testing.T) { func TestBackup(t *testing.T) {
if !RunIntegrationTest { if !RunIntegrationTest {
t.Skip("integration tests disabled, use `-test.integration` to enable") t.Skip("integration tests disabled")
} }
datafile := filepath.Join("testdata", "backup-data.tar.gz") datafile := filepath.Join("testdata", "backup-data.tar.gz")

View file

@ -18,6 +18,8 @@ var (
TestCleanup = getBoolVar("RESTIC_TEST_CLEANUP", true) TestCleanup = getBoolVar("RESTIC_TEST_CLEANUP", true)
TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "") TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "")
RunIntegrationTest = getBoolVar("RESTIC_TEST_INTEGRATION", true) RunIntegrationTest = getBoolVar("RESTIC_TEST_INTEGRATION", true)
TestSFTPPath = getStringVar("RESTIC_TEST_SFTPPATH",
"/usr/lib/ssh:/usr/lib/openssh")
) )
func getStringVar(name, defaultValue string) string { func getStringVar(name, defaultValue string) string {