2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-31 16:10:49 +00:00

Remove flags from tests

This commit is contained in:
Alexander Neumann 2015-06-13 12:35:19 +02:00
parent 002c7883c3
commit 030f08a410
7 changed files with 44 additions and 20 deletions

View File

@ -102,7 +102,7 @@ func testBackend(b backend.Backend, t *testing.T) {
}
// remove content if requested
if *TestCleanup {
if TestCleanup {
for _, test := range TestStrings {
id, err := backend.ParseID(test.id)
OK(t, err)

View File

@ -22,7 +22,7 @@ func setupLocalBackend(t *testing.T) *local.Local {
}
func teardownLocalBackend(t *testing.T, b *local.Local) {
if !*TestCleanup {
if !TestCleanup {
t.Logf("leaving local backend at %s\n", b.Location())
return
}

View File

@ -25,7 +25,7 @@ func setupSFTPBackend(t *testing.T) *sftp.SFTP {
}
func teardownSFTPBackend(t *testing.T, b *sftp.SFTP) {
if !*TestCleanup {
if !TestCleanup {
t.Logf("leaving backend at %s\n", b.Location())
return
}
@ -35,7 +35,7 @@ func teardownSFTPBackend(t *testing.T, b *sftp.SFTP) {
}
func TestSFTPBackend(t *testing.T) {
if !*RunIntegrationTest {
if !RunIntegrationTest {
t.Skip("integration tests disabled, use `-test.integration` to enable")
}

View File

@ -17,7 +17,7 @@ import (
var TestDataFile = flag.String("test.datafile", "", `specify tar.gz file with test data to backup and restore (required for integration test)`)
func setupTempdir(t testing.TB) (tempdir string) {
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
OK(t, err)
return tempdir
@ -28,11 +28,11 @@ func configureRestic(t testing.TB, tempdir string) {
opts.Repo = filepath.Join(tempdir, "repo")
opts.Quiet = true
opts.password = *TestPassword
opts.password = TestPassword
}
func cleanupTempdir(t testing.TB, tempdir string) {
if !*TestCleanup {
if !TestCleanup {
t.Logf("leaving temporary directory %v used for test", tempdir)
return
}
@ -116,7 +116,7 @@ func cmdFsck(t testing.TB) {
}
func TestBackup(t *testing.T) {
if !*RunIntegrationTest {
if !RunIntegrationTest {
t.Skip("integration tests disabled, use `-test.integration` to enable")
}

View File

@ -103,11 +103,11 @@ var nodeTests = []restic.Node{
}
func TestNodeRestoreAt(t *testing.T) {
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
OK(t, err)
defer func() {
if *TestCleanup {
if TestCleanup {
OK(t, os.RemoveAll(tempdir))
} else {
t.Logf("leaving tempdir at %v", tempdir)

View File

@ -1,8 +1,9 @@
package test_helper
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
@ -13,14 +14,37 @@ import (
)
var (
TestPassword = flag.String("test.password", "geheim", `use this password for repositories created during tests (default: "geheim")`)
TestCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)")
TestTempDir = flag.String("test.tempdir", "", "use this directory for temporary storage (default: system temp dir)")
RunIntegrationTest = flag.Bool("test.integration", false, "run integration tests (default: false)")
TestPassword = getStringVar("RESTIC_TEST_PASSWORD", "geheim")
TestCleanup = getBoolVar("RESTIC_TEST_CLEANUP", true)
TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "")
RunIntegrationTest = getBoolVar("RESTIC_TEST_INTEGRATION", true)
)
func getStringVar(name, defaultValue string) string {
if e := os.Getenv(name); e != "" {
return e
}
return defaultValue
}
func getBoolVar(name string, defaultValue bool) bool {
if e := os.Getenv(name); e != "" {
switch e {
case "1":
return true
case "0":
return false
default:
fmt.Fprintf(os.Stderr, "invalid value for variable %q, using default\n", name)
}
}
return defaultValue
}
func SetupRepo(t testing.TB) *repository.Repository {
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
OK(t, err)
// create repository below temp dir
@ -28,12 +52,12 @@ func SetupRepo(t testing.TB) *repository.Repository {
OK(t, err)
repo := repository.New(b)
OK(t, repo.Init(*TestPassword))
OK(t, repo.Init(TestPassword))
return repo
}
func TeardownRepo(t testing.TB, repo *repository.Repository) {
if !*TestCleanup {
if !TestCleanup {
l := repo.Backend().(*local.Local)
t.Logf("leaving local backend at %s\n", l.Location())
return

View File

@ -22,7 +22,7 @@ var testFiles = []struct {
}
func createTempDir(t *testing.T) string {
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
OK(t, err)
for _, test := range testFiles {
@ -49,7 +49,7 @@ func createTempDir(t *testing.T) string {
func TestTree(t *testing.T) {
dir := createTempDir(t)
defer func() {
if *TestCleanup {
if TestCleanup {
OK(t, os.RemoveAll(dir))
}
}()