From 9853fbcf4859314b2c751deb8976c2f69c2a5ecc Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 13 Jun 2015 13:16:43 +0200 Subject: [PATCH] Remove more flags from tests --- backend/sftp_test.go | 33 ++++++++++++++++++++++++--------- cmd/restic/integration_test.go | 2 +- test/backend.go | 2 ++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/backend/sftp_test.go b/backend/sftp_test.go index aa262176d..b678e8ea9 100644 --- a/backend/sftp_test.go +++ b/backend/sftp_test.go @@ -1,22 +1,37 @@ package backend_test import ( - "flag" "io/ioutil" "os" + "path/filepath" + "strings" "testing" "github.com/restic/restic/backend/sftp" . "github.com/restic/restic/test" ) -var sftpPath = flag.String("test.sftppath", "", "sftp binary path (default: empty)") - 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-") OK(t, err) - b, err := sftp.Create(tempdir, *sftpPath) + b, err := sftp.Create(tempdir, sftpserver) OK(t, err) 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) { if !RunIntegrationTest { - t.Skip("integration tests disabled, use `-test.integration` to enable") - } - - if *sftpPath == "" { - t.Skipf("sftppath not set, skipping TestSFTPBackend") + t.Skip("integration tests disabled") } s := setupSFTPBackend(t) + if s == nil { + t.Skip("unable to find sftp-server binary") + return + } defer teardownSFTPBackend(t, s) testBackend(s, t) diff --git a/cmd/restic/integration_test.go b/cmd/restic/integration_test.go index 0a77517e4..ac5f921bf 100644 --- a/cmd/restic/integration_test.go +++ b/cmd/restic/integration_test.go @@ -114,7 +114,7 @@ func cmdFsck(t testing.TB) { func TestBackup(t *testing.T) { 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") diff --git a/test/backend.go b/test/backend.go index 9baa3f220..bcf874c0f 100644 --- a/test/backend.go +++ b/test/backend.go @@ -18,6 +18,8 @@ var ( TestCleanup = getBoolVar("RESTIC_TEST_CLEANUP", true) TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "") RunIntegrationTest = getBoolVar("RESTIC_TEST_INTEGRATION", true) + TestSFTPPath = getStringVar("RESTIC_TEST_SFTPPATH", + "/usr/lib/ssh:/usr/lib/openssh") ) func getStringVar(name, defaultValue string) string {