MCPcopy
hub / github.com/kopia/kopia / TestSnapshotFix

Function TestSnapshotFix

cli/command_snapshot_fix_test.go:23–363  ·  view source on GitHub ↗

nolint:maintidx

(t *testing.T)

Source from the content-addressed store, hash-verified

21
22//nolint:maintidx
23func TestSnapshotFix(t *testing.T) {
24 srcDir1 := testutil.TempDirectory(t)
25
26 if testutil.ShouldReduceTestComplexity() {
27 return
28 }
29
30 // 300 bytes
31 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "small-file1"), 1, bytes.Repeat([]byte{1, 2, 3}, 100))
32 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "small-file1-dup"), 1, bytes.Repeat([]byte{1, 2, 3}, 100))
33 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "small-file2"), 1, bytes.Repeat([]byte{1, 2, 4}, 100))
34
35 require.NoError(t, os.MkdirAll(filepath.Join(srcDir1, "dir1"), 0o700))
36 require.NoError(t, os.MkdirAll(filepath.Join(srcDir1, "dir2"), 0o700))
37
38 // 3 x 3 x 1_000_000 bytes = 9 MB
39 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "large-file1"), 3, bytes.Repeat([]byte{1, 2, 3}, 1000000))
40 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "large-file1-dup"), 3, bytes.Repeat([]byte{1, 2, 3}, 1000000))
41 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "large-file2"), 3, bytes.Repeat([]byte{1, 2, 4}, 1000000))
42
43 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir1", "small-file1"), 1, bytes.Repeat([]byte{1, 1, 2, 3}, 100))
44 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir1", "small-file1-dup"), 1, bytes.Repeat([]byte{1, 1, 2, 3}, 100))
45 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir1", "small-file2"), 1, bytes.Repeat([]byte{1, 1, 2, 4}, 100))
46 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir1", "large-file1"), 3, bytes.Repeat([]byte{1, 1, 2, 3}, 1000000))
47 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir1", "large-file1-dup"), 3, bytes.Repeat([]byte{1, 1, 2, 3}, 1000000))
48 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir1", "large-file2"), 3, bytes.Repeat([]byte{1, 1, 2, 4}, 1000000))
49
50 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir2", "small-file1"), 1, bytes.Repeat([]byte{2, 1, 2, 3}, 100))
51 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir2", "small-file1-dup"), 1, bytes.Repeat([]byte{2, 1, 2, 3}, 100))
52 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir2", "small-file2"), 1, bytes.Repeat([]byte{2, 1, 2, 4}, 100))
53 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir2", "large-file1"), 3, bytes.Repeat([]byte{2, 1, 2, 3}, 1000000))
54 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir2", "large-file1-dup"), 3, bytes.Repeat([]byte{2, 1, 2, 3}, 1000000))
55 mustWriteFileWithRepeatedData(t, filepath.Join(srcDir1, "dir2", "large-file2"), 3, bytes.Repeat([]byte{2, 1, 2, 4}, 1000000))
56
57 cases := []struct {
58 name string
59 flags []string
60 modifyRepoAfterSnapshot func(env *testenv.CLITest, man *snapshot.Manifest, fileMap map[string]*snapshot.DirEntry)
61 initiallyCorrupted bool
62 wantRecoveredFiles []string
63 wantRootStub bool
64 wantFixFail bool
65 wantFailVerify bool
66 }{
67 {
68 name: "FixInvalidFiles_NoOp",
69 modifyRepoAfterSnapshot: func(env *testenv.CLITest, man *snapshot.Manifest, fileMap map[string]*snapshot.DirEntry) {},
70 flags: []string{"invalid-files"},
71 wantRecoveredFiles: []string{
72 "dir1",
73 "dir1/large-file1",
74 "dir1/large-file1-dup",
75 "dir1/large-file2",
76 "dir1/small-file1",
77 "dir1/small-file1-dup",
78 "dir1/small-file2",
79 "dir2",
80 "dir2/large-file1",

Callers

nothing calls this directly

Calls 15

RootObjectIDMethod · 0.95
RunAndExpectSuccessMethod · 0.95
RunAndExpectFailureMethod · 0.95
TempDirectoryFunction · 0.92
NewInProcRunnerFunction · 0.92
NewCLITestFunction · 0.92
MustParseJSONLinesFunction · 0.92
forgetContentsFunction · 0.85
mustGetFileMapFunction · 0.85
RepeatMethod · 0.80

Tested by

no test coverage detected