integration tests: Deduplicate backup test-data setup code
This commit is contained in:
parent
ec9a53b7e8
commit
591a8c4cdf
1 changed files with 16 additions and 69 deletions
|
@ -260,22 +260,18 @@ func testRunPrune(t testing.TB, gopts GlobalOptions) {
|
||||||
rtest.OK(t, runPrune(gopts))
|
rtest.OK(t, runPrune(gopts))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testSetupBackupData(t testing.TB, env *testEnvironment) string {
|
||||||
|
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
||||||
|
testRunInit(t, env.gopts)
|
||||||
|
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
||||||
|
return datafile
|
||||||
|
}
|
||||||
|
|
||||||
func TestBackup(t *testing.T) {
|
func TestBackup(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
testSetupBackupData(t, env)
|
||||||
fd, err := os.Open(datafile)
|
|
||||||
if os.IsNotExist(errors.Cause(err)) {
|
|
||||||
t.Skipf("unable to find data file %q, skipping", datafile)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rtest.OK(t, err)
|
|
||||||
rtest.OK(t, fd.Close())
|
|
||||||
|
|
||||||
testRunInit(t, env.gopts)
|
|
||||||
|
|
||||||
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
|
||||||
opts := BackupOptions{}
|
opts := BackupOptions{}
|
||||||
|
|
||||||
// first backup
|
// first backup
|
||||||
|
@ -329,18 +325,7 @@ func TestBackupNonExistingFile(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
testSetupBackupData(t, env)
|
||||||
fd, err := os.Open(datafile)
|
|
||||||
if os.IsNotExist(errors.Cause(err)) {
|
|
||||||
t.Skipf("unable to find data file %q, skipping", datafile)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rtest.OK(t, err)
|
|
||||||
rtest.OK(t, fd.Close())
|
|
||||||
|
|
||||||
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
|
||||||
|
|
||||||
testRunInit(t, env.gopts)
|
|
||||||
globalOptions.stderr = ioutil.Discard
|
globalOptions.stderr = ioutil.Discard
|
||||||
defer func() {
|
defer func() {
|
||||||
globalOptions.stderr = os.Stderr
|
globalOptions.stderr = os.Stderr
|
||||||
|
@ -503,11 +488,7 @@ func TestBackupErrors(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
testSetupBackupData(t, env)
|
||||||
|
|
||||||
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
|
||||||
|
|
||||||
testRunInit(t, env.gopts)
|
|
||||||
|
|
||||||
// Assume failure
|
// Assume failure
|
||||||
inaccessibleFile := filepath.Join(env.testdata, "0", "0", "9", "0")
|
inaccessibleFile := filepath.Join(env.testdata, "0", "0", "9", "0")
|
||||||
|
@ -596,10 +577,7 @@ func TestBackupTags(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
testSetupBackupData(t, env)
|
||||||
testRunInit(t, env.gopts)
|
|
||||||
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
|
||||||
|
|
||||||
opts := BackupOptions{}
|
opts := BackupOptions{}
|
||||||
|
|
||||||
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
||||||
|
@ -630,10 +608,7 @@ func TestTag(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
testSetupBackupData(t, env)
|
||||||
testRunInit(t, env.gopts)
|
|
||||||
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
|
||||||
|
|
||||||
testRunBackup(t, "", []string{env.testdata}, BackupOptions{}, env.gopts)
|
testRunBackup(t, "", []string{env.testdata}, BackupOptions{}, env.gopts)
|
||||||
testRunCheck(t, env.gopts)
|
testRunCheck(t, env.gopts)
|
||||||
newest, _ := testRunSnapshots(t, env.gopts)
|
newest, _ := testRunSnapshots(t, env.gopts)
|
||||||
|
@ -1033,10 +1008,7 @@ func TestFind(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
datafile := testSetupBackupData(t, env)
|
||||||
testRunInit(t, env.gopts)
|
|
||||||
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
|
||||||
|
|
||||||
opts := BackupOptions{}
|
opts := BackupOptions{}
|
||||||
|
|
||||||
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
||||||
|
@ -1073,10 +1045,7 @@ func TestFindJSON(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
datafile := testSetupBackupData(t, env)
|
||||||
testRunInit(t, env.gopts)
|
|
||||||
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
|
||||||
|
|
||||||
opts := BackupOptions{}
|
opts := BackupOptions{}
|
||||||
|
|
||||||
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
testRunBackup(t, "", []string{env.testdata}, opts, env.gopts)
|
||||||
|
@ -1199,18 +1168,7 @@ func TestPrune(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
testSetupBackupData(t, env)
|
||||||
fd, err := os.Open(datafile)
|
|
||||||
if os.IsNotExist(errors.Cause(err)) {
|
|
||||||
t.Skipf("unable to find data file %q, skipping", datafile)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rtest.OK(t, err)
|
|
||||||
rtest.OK(t, fd.Close())
|
|
||||||
|
|
||||||
testRunInit(t, env.gopts)
|
|
||||||
|
|
||||||
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
|
||||||
opts := BackupOptions{}
|
opts := BackupOptions{}
|
||||||
|
|
||||||
testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9")}, opts, env.gopts)
|
testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9")}, opts, env.gopts)
|
||||||
|
@ -1385,18 +1343,7 @@ func TestQuietBackup(t *testing.T) {
|
||||||
env, cleanup := withTestEnvironment(t)
|
env, cleanup := withTestEnvironment(t)
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
datafile := filepath.Join("testdata", "backup-data.tar.gz")
|
testSetupBackupData(t, env)
|
||||||
fd, err := os.Open(datafile)
|
|
||||||
if os.IsNotExist(errors.Cause(err)) {
|
|
||||||
t.Skipf("unable to find data file %q, skipping", datafile)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
rtest.OK(t, err)
|
|
||||||
rtest.OK(t, fd.Close())
|
|
||||||
|
|
||||||
testRunInit(t, env.gopts)
|
|
||||||
|
|
||||||
rtest.SetupTarTestFixture(t, env.testdata, datafile)
|
|
||||||
opts := BackupOptions{}
|
opts := BackupOptions{}
|
||||||
|
|
||||||
env.gopts.Quiet = false
|
env.gopts.Quiet = false
|
||||||
|
|
Loading…
Reference in a new issue