MCPcopy
hub / github.com/kopia/kopia / TestSnapshotVerify

Function TestSnapshotVerify

cli/command_snapshot_verify_test.go:19–141  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

17)
18
19func TestSnapshotVerify(t *testing.T) {
20 srcDir1 := testutil.TempDirectory(t)
21
22 runner := testenv.NewInProcRunner(t)
23 env := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
24
25 env.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", env.RepoDir)
26
27 var intactMan, corruptMan1, corruptMan2 snapshot.Manifest
28
29 // Write a file, create a new snapshot.
30 intactFileName := "intact"
31 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, intactFileName), 1, bytes.Repeat([]byte{1, 2, 3}, 100))
32 testutil.MustParseJSONLines(t, env.RunAndExpectSuccess(t, "snapshot", "create", srcDir1, "--json"), &intactMan)
33
34 // Write a new file not present in the previous snapshot.
35 corruptFileName1 := "corrupt1"
36 pattern1 := []byte{1, 2, 4}
37 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, corruptFileName1), 1, bytes.Repeat(pattern1, 100))
38
39 // Create a snapshot including the new file.
40 testutil.MustParseJSONLines(t, env.RunAndExpectSuccess(t, "snapshot", "create", srcDir1, "--json"), &corruptMan1)
41
42 // Write a new file not present in the previous two snapshots. Use a data pattern
43 // distinct from the previous file to prevent dedup.
44 corruptFileName2 := "corrupt2"
45 pattern2 := []byte{1, 2, 5}
46 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, corruptFileName2), 1, bytes.Repeat(pattern2, 100))
47
48 // Create a snapshot including the new file.
49 testutil.MustParseJSONLines(t, env.RunAndExpectSuccess(t, "snapshot", "create", srcDir1, "--json"), &corruptMan2)
50
51 // Corrupt the blobs containing the contents associated with the files to be corrupted.
52 fileMap := mustGetFileMap(t, env, corruptMan2.RootObjectID())
53 forgetContents(t, env, fileMap[corruptFileName1].ObjectID.String())
54 forgetContents(t, env, fileMap[corruptFileName2].ObjectID.String())
55
56 // Verifying everything is expected to fail.
57 env.RunAndExpectFailure(t, "snapshot", "verify")
58
59 // Verifying the untouched snapshot is expected to succeed.
60 env.RunAndExpectSuccess(t, "snapshot", "verify", string(intactMan.ID))
61
62 // Verifying the corrupted snapshot is expected to fail.
63 env.RunAndExpectFailure(t, "snapshot", "verify", string(corruptMan1.ID))
64
65 // Verifying the corrupted snapshot is expected to fail.
66 env.RunAndExpectFailure(t, "snapshot", "verify", string(corruptMan2.ID))
67
68 // Find one matching error corresponding to the single corrupted contents.
69 _, stderr, err := env.Run(t, true, "snapshot", "verify", "--max-errors", "3", string(corruptMan1.ID))
70 require.Error(t, err)
71 assert.Equal(t, 1, strings.Count(strings.Join(stderr, "\n"), "error processing"))
72
73 // Find two matching errors in the verify output, corresponding to each
74 // of the two corrupted contents.
75 _, stderr, err = env.Run(t, true, "snapshot", "verify", "--max-errors", "3", string(corruptMan2.ID))
76 require.Error(t, err)

Callers

nothing calls this directly

Calls 15

RunAndExpectSuccessMethod · 0.95
RootObjectIDMethod · 0.95
RunAndExpectFailureMethod · 0.95
RunMethod · 0.95
TempDirectoryFunction · 0.92
NewInProcRunnerFunction · 0.92
NewCLITestFunction · 0.92
MustParseJSONLinesFunction · 0.92
mustGetFileMapFunction · 0.85
forgetContentsFunction · 0.85
unmarshalSnapVerifyFunction · 0.85

Tested by

no test coverage detected