MCPcopy
hub / github.com/kopia/kopia / TestDiff

Function TestDiff

tests/end_to_end_test/diff_test.go:15–74  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

13)
14
15func TestDiff(t *testing.T) {
16 t.Parallel()
17
18 runner := testenv.NewInProcRunner(t)
19 e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner)
20
21 defer e.RunAndExpectSuccess(t, "repo", "disconnect")
22
23 e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir)
24
25 dataDir := testutil.TempDirectory(t)
26
27 // initial snapshot
28 require.NoError(t, os.MkdirAll(dataDir, 0o777))
29 e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
30
31 // create some directories and files
32 require.NoError(t, os.MkdirAll(filepath.Join(dataDir, "foo"), 0o700))
33 require.NoError(t, os.WriteFile(filepath.Join(dataDir, "some-file1"), []byte(`
34hello world
35how are you
36`), 0o600))
37 require.NoError(t, os.WriteFile(filepath.Join(dataDir, "some-file2"), []byte(`
38quick brown
39fox jumps
40over the lazy
41dog
42`), 0o600))
43 e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
44
45 // change some files
46 require.NoError(t, os.WriteFile(filepath.Join(dataDir, "some-file2"), []byte(`
47quick brown
48fox jumps
49over the lazy
50canary
51`), 0o600))
52
53 require.NoError(t, os.MkdirAll(filepath.Join(dataDir, "bar"), 0o700))
54 e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
55
56 // change some files
57 os.Remove(filepath.Join(dataDir, "some-file1"))
58
59 require.NoError(t, os.MkdirAll(filepath.Join(dataDir, "bar"), 0o700))
60 e.RunAndExpectSuccess(t, "snapshot", "create", dataDir)
61
62 si := clitestutil.ListSnapshotsAndExpectSuccess(t, e, dataDir)
63 if got, want := len(si), 1; got != want {
64 t.Fatalf("got %v sources, wanted %v", got, want)
65 }
66
67 // make sure we can generate between all versions of the directory
68 snapshots := si[0].Snapshots
69 for _, s1 := range snapshots {
70 for _, s2 := range snapshots {
71 e.RunAndExpectSuccess(t, "diff", "-f", s1.ObjectID, s2.ObjectID)
72 }

Callers

nothing calls this directly

Calls 9

RunAndExpectSuccessMethod · 0.95
NewInProcRunnerFunction · 0.92
NewCLITestFunction · 0.92
TempDirectoryFunction · 0.92
FatalfMethod · 0.80
MkdirAllMethod · 0.65
WriteFileMethod · 0.65
RemoveMethod · 0.65

Tested by

no test coverage detected