MCPcopy
hub / github.com/kopia/kopia / TestSnapshotPin

Function TestSnapshotPin

cli/command_snapshot_pin_test.go:16–82  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestSnapshotPin(t *testing.T) {
17 t.Parallel()
18
19 runner := testenv.NewInProcRunner(t)
20 e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
21
22 defer e.RunAndExpectSuccess(t, "repo", "disconnect")
23
24 e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
25
26 srcdir := testutil.TempDirectory(t)
27 require.NoError(t, os.WriteFile(filepath.Join(srcdir, "some-file2"), []byte{1, 2, 3}, 0o755))
28
29 var man snapshot.Manifest
30
31 e.RunAndExpectSuccess(t, "policy", "set", srcdir, "--keep-latest=3", "--keep-hourly=0", "--keep-daily=0", "--keep-monthly=0", "--keep-weekly=0", "--keep-annual=0")
32
33 testutil.MustParseJSONLines(t, e.RunAndExpectSuccess(t, "snapshot", "create", srcdir, "--pin=a", "--pin=b", "--json"), &man)
34 require.Equal(t, []string{"a", "b"}, man.Pins)
35
36 e.RunAndExpectSuccess(t, "snapshot", "list")
37
38 // create more unpinned snapshots
39 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
40 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
41 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
42 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
43 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
44
45 snapshots := mustListSnapshots(t, e)
46
47 // make sure the pinned one is on top.
48 require.Len(t, snapshots, 4)
49 require.Equal(t, []string{"a", "b"}, snapshots[0].Pins)
50 require.Empty(t, snapshots[1].Pins)
51 require.Empty(t, snapshots[2].Pins)
52 require.Empty(t, snapshots[3].Pins)
53
54 // neither --add nor --remove were provided
55 e.RunAndExpectFailure(t, "snapshot", "pin", string(snapshots[3].ID))
56 e.RunAndExpectSuccess(t, "snapshot", "pin", string(snapshots[0].ID), "--add=c", "--remove=b")
57 e.RunAndExpectSuccess(t, "snapshot", "pin", string(snapshots[3].ID), "--add=d")
58
59 snapshots2 := mustListSnapshots(t, e)
60
61 require.Len(t, snapshots2, 4)
62 require.Equal(t, []string{"a", "c"}, snapshots2[0].Pins)
63 require.Empty(t, snapshots2[1].Pins)
64 require.Empty(t, snapshots2[2].Pins)
65 require.Equal(t, []string{"d"}, snapshots2[3].Pins)
66
67 // create more unpinned snapshots
68 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
69 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
70 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
71 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
72 e.RunAndExpectSuccess(t, "snapshot", "create", srcdir)
73

Callers

nothing calls this directly

Calls 10

RunAndExpectSuccessMethod · 0.95
RunAndExpectFailureMethod · 0.95
NewInProcRunnerFunction · 0.92
NewCLITestFunction · 0.92
TempDirectoryFunction · 0.92
MustParseJSONLinesFunction · 0.92
mustListSnapshotsFunction · 0.85
EqualMethod · 0.80
WriteFileMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected