mirror of
https://github.com/restic/restic.git
synced 2026-05-28 04:35:41 -04:00
copy --group-by - new tests
New tests have been developed to check out the new options --group-by in conjuction with --latest 'n'.
This commit is contained in:
parent
1c9f0b5c36
commit
0801c9243a
1 changed files with 111 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/restic/restic/internal/data"
|
||||
"github.com/restic/restic/internal/global"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
|
|
@ -30,6 +31,27 @@ func testRunCopy(t testing.TB, srcGopts global.Options, dstGopts global.Options)
|
|||
}))
|
||||
}
|
||||
|
||||
func testRunCopyWithWrapper(t testing.TB, srcGopts global.Options, dstGopts global.Options,
|
||||
wrap func(opts *CopyOptions),
|
||||
) {
|
||||
gopts := srcGopts
|
||||
gopts.Repo = dstGopts.Repo
|
||||
gopts.Password = dstGopts.Password
|
||||
gopts.InsecureNoPassword = dstGopts.InsecureNoPassword
|
||||
copyOpts := CopyOptions{
|
||||
SecondaryRepoOptions: global.SecondaryRepoOptions{
|
||||
Repo: srcGopts.Repo,
|
||||
Password: srcGopts.Password,
|
||||
InsecureNoPassword: srcGopts.InsecureNoPassword,
|
||||
},
|
||||
}
|
||||
|
||||
rtest.OK(t, withTermStatus(t, gopts, func(ctx context.Context, gopts global.Options) error {
|
||||
wrap(©Opts)
|
||||
return runCopy(context.TODO(), copyOpts, gopts, nil, gopts.Term)
|
||||
}))
|
||||
}
|
||||
|
||||
func TestCopy(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
|
|
@ -195,3 +217,92 @@ func TestCopyToEmptyPassword(t *testing.T) {
|
|||
testListSnapshots(t, env2.gopts, 1)
|
||||
testRunCheck(t, env2.gopts)
|
||||
}
|
||||
|
||||
func testRunSixBackups(t *testing.T, env *testEnvironment) {
|
||||
opts := BackupOptions{
|
||||
Host: "asterix",
|
||||
}
|
||||
testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9", "10")}, opts, env.gopts)
|
||||
testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9", "20")}, opts, env.gopts)
|
||||
|
||||
opts = BackupOptions{
|
||||
Host: "obelix",
|
||||
}
|
||||
testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9", "10")}, opts, env.gopts)
|
||||
testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9", "20")}, opts, env.gopts)
|
||||
|
||||
opts = BackupOptions{
|
||||
Host: "idefix",
|
||||
}
|
||||
testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9", "10")}, opts, env.gopts)
|
||||
testRunBackup(t, "", []string{filepath.Join(env.testdata, "0", "0", "9", "20")}, opts, env.gopts)
|
||||
|
||||
// make sure that we have got 6 snapsshots
|
||||
testListSnapshots(t, env.gopts, 6)
|
||||
}
|
||||
|
||||
func TestCopyGroupByPath(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
env2, cleanup2 := withTestEnvironment(t)
|
||||
defer cleanup2()
|
||||
|
||||
testSetupBackupData(t, env)
|
||||
testRunSixBackups(t, env)
|
||||
|
||||
testRunInit(t, env2.gopts)
|
||||
testRunCopyWithWrapper(t, env.gopts, env2.gopts, func(opts *CopyOptions) {
|
||||
opts.latest = 1
|
||||
opts.GroupBy = data.SnapshotGroupByOptions{Path: true}
|
||||
})
|
||||
|
||||
// make sure that we have got 2 snapsshots
|
||||
testListSnapshots(t, env2.gopts, 2)
|
||||
|
||||
// make sure that subsequent copy operations with the same options
|
||||
// does nothing to the target repository
|
||||
testRunCopyWithWrapper(t, env.gopts, env2.gopts, func(opts *CopyOptions) {
|
||||
opts.latest = 1
|
||||
opts.GroupBy = data.SnapshotGroupByOptions{Path: true}
|
||||
})
|
||||
|
||||
testListSnapshots(t, env2.gopts, 2)
|
||||
}
|
||||
|
||||
func TestCopyGroupByHost(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
env2, cleanup2 := withTestEnvironment(t)
|
||||
defer cleanup2()
|
||||
|
||||
testSetupBackupData(t, env)
|
||||
testRunSixBackups(t, env)
|
||||
|
||||
testRunInit(t, env2.gopts)
|
||||
testRunCopyWithWrapper(t, env.gopts, env2.gopts, func(opts *CopyOptions) {
|
||||
opts.latest = 1
|
||||
opts.GroupBy = data.SnapshotGroupByOptions{Host: true}
|
||||
})
|
||||
|
||||
// make sure that we have got 3 snapsshots
|
||||
testListSnapshots(t, env2.gopts, 3)
|
||||
}
|
||||
|
||||
func TestCopyGroupByHostAndPath(t *testing.T) {
|
||||
env, cleanup := withTestEnvironment(t)
|
||||
defer cleanup()
|
||||
env2, cleanup2 := withTestEnvironment(t)
|
||||
defer cleanup2()
|
||||
|
||||
testSetupBackupData(t, env)
|
||||
testRunSixBackups(t, env)
|
||||
|
||||
testRunInit(t, env2.gopts)
|
||||
testRunCopyWithWrapper(t, env.gopts, env2.gopts, func(opts *CopyOptions) {
|
||||
opts.latest = 1
|
||||
opts.GroupBy = data.SnapshotGroupByOptions{Host: true, Path: true}
|
||||
})
|
||||
|
||||
// make sure that we have got 6 snapsshots
|
||||
testListSnapshots(t, env2.gopts, 6)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue