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
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)

View File

@ -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")

View File

@ -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 {