(t *testing.T)
| 14 | ) |
| 15 | |
| 16 | func 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, |
nothing calls this directly
no test coverage detected