MCPcopy Index your code
hub / github.com/kopia/kopia / TestSnapshotStorageStats

Function TestSnapshotStorageStats

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

Source from the content-addressed store, hash-verified

14)
15
16func TestSnapshotStorageStats(t *testing.T) {
17 env := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t))
18
19 dir1 := testutil.TempDirectory(t)
20 require.NoError(t, os.WriteFile(filepath.Join(dir1, "file1.txt"), []byte{1, 2, 3, 4, 5}, 0o600))
21 require.NoError(t, os.WriteFile(filepath.Join(dir1, "file2.txt"), []byte{2, 3, 4, 5, 6}, 0o600))
22 require.NoError(t, os.MkdirAll(filepath.Join(dir1, "subdir"), 0o755))
23 require.NoError(t, os.WriteFile(filepath.Join(dir1, "subdir", "file2.txt"), []byte{3, 4, 5, 6, 7}, 0o600))
24
25 env.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", env.RepoDir)
26 env.RunAndExpectSuccess(t, "snapshot", "create", dir1)
27
28 // same as ./file1.txt
29 require.NoError(t, os.WriteFile(filepath.Join(dir1, "subdir", "file3.txt"), []byte{1, 2, 3, 4, 5}, 0o600))
30
31 // new file
32 require.NoError(t, os.WriteFile(filepath.Join(dir1, "subdir", "file4.txt"), []byte{1, 2, 3, 4, 5, 6, 7, 8}, 0o600))
33 env.RunAndExpectSuccess(t, "snapshot", "create", dir1)
34
35 var manifests []cli.SnapshotManifest
36
37 testutil.MustParseJSONLines(t, env.RunAndExpectSuccess(t, "snapshot", "ls", "--storage-stats", dir1, "--json"), &manifests)
38 require.Len(t, manifests, 2)
39
40 require.Equal(t, &snapshot.StorageStats{
41 NewData: snapshot.StorageUsageDetails{
42 FileObjectCount: 3,
43 DirObjectCount: 2,
44 ContentCount: 5,
45 ObjectBytes: 15,
46 OriginalContentBytes: 15,
47 PackedContentBytes: 99,
48 },
49 RunningTotal: snapshot.StorageUsageDetails{
50 FileObjectCount: 3,
51 DirObjectCount: 2,
52 ContentCount: 5,
53 ObjectBytes: 15,
54 OriginalContentBytes: 15,
55 PackedContentBytes: 99,
56 },
57 }, manifests[0].StorageStats)
58
59 require.Equal(t, &snapshot.StorageStats{
60 NewData: snapshot.StorageUsageDetails{
61 FileObjectCount: 1,
62 DirObjectCount: 2,
63 ContentCount: 3,
64 ObjectBytes: 8,
65 OriginalContentBytes: 8,
66 PackedContentBytes: 36,
67 },
68 RunningTotal: snapshot.StorageUsageDetails{
69 FileObjectCount: 4,
70 DirObjectCount: 4,
71 ContentCount: 8,
72 ObjectBytes: 23,
73 OriginalContentBytes: 23,

Callers

nothing calls this directly

Calls 10

RunAndExpectSuccessMethod · 0.95
NewCLITestFunction · 0.92
NewInProcRunnerFunction · 0.92
TempDirectoryFunction · 0.92
MustParseJSONLinesFunction · 0.92
EqualMethod · 0.80
WriteFileMethod · 0.65
MkdirAllMethod · 0.65
LenMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected