From 6ae2b4f6793e4aeec06784798b3d2c6a1d7f58b1 Mon Sep 17 00:00:00 2001 From: Winfried Plappert <18740761+wplapper@users.noreply.github.com> Date: Tue, 19 May 2026 07:45:54 +0100 Subject: [PATCH] copy --latest - test added test for stand-alone --latest option --- cmd/restic/cmd_copy_integration_test.go | 27 ++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/cmd/restic/cmd_copy_integration_test.go b/cmd/restic/cmd_copy_integration_test.go index 218546bba..3215ff68e 100644 --- a/cmd/restic/cmd_copy_integration_test.go +++ b/cmd/restic/cmd_copy_integration_test.go @@ -288,7 +288,6 @@ func TestCopyGroupByHost(t *testing.T) { }) rtest.OK(t, err) - // make sure that we have got 3 snapsshots testListSnapshots(t, env2.gopts, 3) } @@ -308,10 +307,27 @@ func TestCopyGroupByHostAndPath(t *testing.T) { }) rtest.OK(t, err) - // make sure that we have got 6 snapsshots testListSnapshots(t, env2.gopts, 6) } +func TestCopyLatest(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) + err := testRunCopyWithWrapperMayFail(t, env.gopts, env2.gopts, func(opts *CopyOptions) { + opts.latest = 3 + }) + rtest.OK(t, err) + + testListSnapshots(t, env2.gopts, 3) +} + func TestCopyGroupByHostFailure(t *testing.T) { env, cleanup := withTestEnvironment(t) defer cleanup() @@ -328,11 +344,4 @@ func TestCopyGroupByHostFailure(t *testing.T) { rtest.Assert(t, err != nil, "expected error, got none") rtest.Assert(t, strings.Contains(err.Error(), "you need to specify --latest `n`"), "expected error message %q", "you need to specify --latest `n` ...") - - err = testRunCopyWithWrapperMayFail(t, env.gopts, env2.gopts, func(opts *CopyOptions) { - opts.latest = 1 - }) - rtest.Assert(t, err != nil, "expected error, got none") - rtest.Assert(t, strings.Contains(err.Error(), "--latest `n`, has no effect without using --group-by"), - "expected error message %q", "--latest `n`, has no effect without using --group-by") }