forked from TrueCloudLab/restic
Remove flags from tests
This commit is contained in:
parent
002c7883c3
commit
030f08a410
7 changed files with 44 additions and 20 deletions
|
@ -102,7 +102,7 @@ func testBackend(b backend.Backend, t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove content if requested
|
// remove content if requested
|
||||||
if *TestCleanup {
|
if TestCleanup {
|
||||||
for _, test := range TestStrings {
|
for _, test := range TestStrings {
|
||||||
id, err := backend.ParseID(test.id)
|
id, err := backend.ParseID(test.id)
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
|
@ -22,7 +22,7 @@ func setupLocalBackend(t *testing.T) *local.Local {
|
||||||
}
|
}
|
||||||
|
|
||||||
func teardownLocalBackend(t *testing.T, b *local.Local) {
|
func teardownLocalBackend(t *testing.T, b *local.Local) {
|
||||||
if !*TestCleanup {
|
if !TestCleanup {
|
||||||
t.Logf("leaving local backend at %s\n", b.Location())
|
t.Logf("leaving local backend at %s\n", b.Location())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ func setupSFTPBackend(t *testing.T) *sftp.SFTP {
|
||||||
}
|
}
|
||||||
|
|
||||||
func teardownSFTPBackend(t *testing.T, b *sftp.SFTP) {
|
func teardownSFTPBackend(t *testing.T, b *sftp.SFTP) {
|
||||||
if !*TestCleanup {
|
if !TestCleanup {
|
||||||
t.Logf("leaving backend at %s\n", b.Location())
|
t.Logf("leaving backend at %s\n", b.Location())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ 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, use `-test.integration` to enable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)`)
|
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) {
|
func setupTempdir(t testing.TB) (tempdir string) {
|
||||||
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
|
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
return tempdir
|
return tempdir
|
||||||
|
@ -28,11 +28,11 @@ func configureRestic(t testing.TB, tempdir string) {
|
||||||
opts.Repo = filepath.Join(tempdir, "repo")
|
opts.Repo = filepath.Join(tempdir, "repo")
|
||||||
opts.Quiet = true
|
opts.Quiet = true
|
||||||
|
|
||||||
opts.password = *TestPassword
|
opts.password = TestPassword
|
||||||
}
|
}
|
||||||
|
|
||||||
func cleanupTempdir(t testing.TB, tempdir string) {
|
func cleanupTempdir(t testing.TB, tempdir string) {
|
||||||
if !*TestCleanup {
|
if !TestCleanup {
|
||||||
t.Logf("leaving temporary directory %v used for test", tempdir)
|
t.Logf("leaving temporary directory %v used for test", tempdir)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,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, use `-test.integration` to enable")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,11 +103,11 @@ var nodeTests = []restic.Node{
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeRestoreAt(t *testing.T) {
|
func TestNodeRestoreAt(t *testing.T) {
|
||||||
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
|
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if *TestCleanup {
|
if TestCleanup {
|
||||||
OK(t, os.RemoveAll(tempdir))
|
OK(t, os.RemoveAll(tempdir))
|
||||||
} else {
|
} else {
|
||||||
t.Logf("leaving tempdir at %v", tempdir)
|
t.Logf("leaving tempdir at %v", tempdir)
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package test_helper
|
package test_helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -13,14 +14,37 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
TestPassword = flag.String("test.password", "geheim", `use this password for repositories created during tests (default: "geheim")`)
|
TestPassword = getStringVar("RESTIC_TEST_PASSWORD", "geheim")
|
||||||
TestCleanup = flag.Bool("test.cleanup", true, "clean up after running tests (remove local backend directory with all content)")
|
TestCleanup = getBoolVar("RESTIC_TEST_CLEANUP", true)
|
||||||
TestTempDir = flag.String("test.tempdir", "", "use this directory for temporary storage (default: system temp dir)")
|
TestTempDir = getStringVar("RESTIC_TEST_TMPDIR", "")
|
||||||
RunIntegrationTest = flag.Bool("test.integration", false, "run integration tests (default: false)")
|
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 {
|
func SetupRepo(t testing.TB) *repository.Repository {
|
||||||
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
|
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
// create repository below temp dir
|
// create repository below temp dir
|
||||||
|
@ -28,12 +52,12 @@ func SetupRepo(t testing.TB) *repository.Repository {
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
repo := repository.New(b)
|
repo := repository.New(b)
|
||||||
OK(t, repo.Init(*TestPassword))
|
OK(t, repo.Init(TestPassword))
|
||||||
return repo
|
return repo
|
||||||
}
|
}
|
||||||
|
|
||||||
func TeardownRepo(t testing.TB, repo *repository.Repository) {
|
func TeardownRepo(t testing.TB, repo *repository.Repository) {
|
||||||
if !*TestCleanup {
|
if !TestCleanup {
|
||||||
l := repo.Backend().(*local.Local)
|
l := repo.Backend().(*local.Local)
|
||||||
t.Logf("leaving local backend at %s\n", l.Location())
|
t.Logf("leaving local backend at %s\n", l.Location())
|
||||||
return
|
return
|
||||||
|
|
|
@ -22,7 +22,7 @@ var testFiles = []struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func createTempDir(t *testing.T) string {
|
func createTempDir(t *testing.T) string {
|
||||||
tempdir, err := ioutil.TempDir(*TestTempDir, "restic-test-")
|
tempdir, err := ioutil.TempDir(TestTempDir, "restic-test-")
|
||||||
OK(t, err)
|
OK(t, err)
|
||||||
|
|
||||||
for _, test := range testFiles {
|
for _, test := range testFiles {
|
||||||
|
@ -49,7 +49,7 @@ func createTempDir(t *testing.T) string {
|
||||||
func TestTree(t *testing.T) {
|
func TestTree(t *testing.T) {
|
||||||
dir := createTempDir(t)
|
dir := createTempDir(t)
|
||||||
defer func() {
|
defer func() {
|
||||||
if *TestCleanup {
|
if TestCleanup {
|
||||||
OK(t, os.RemoveAll(dir))
|
OK(t, os.RemoveAll(dir))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in a new issue