MCPcopy
hub / github.com/kopia/kopia / TestCompareDifferentDirectories_FileTimeDiff

Function TestCompareDifferentDirectories_FileTimeDiff

internal/diff/diff_test.go:288–336  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

286}
287
288func TestCompareDifferentDirectories_FileTimeDiff(t *testing.T) {
289 var buf bytes.Buffer
290
291 ctx := context.Background()
292
293 fileModTime1 := time.Date(2023, time.April, 12, 10, 30, 0, 0, time.UTC)
294 fileModTime2 := time.Date(2022, time.April, 12, 10, 30, 0, 0, time.UTC)
295 dirModTime := time.Date(2023, time.April, 12, 10, 30, 0, 0, time.UTC)
296 dirOwnerInfo := fs.OwnerInfo{UserID: 1000, GroupID: 1000}
297 dirMode := os.FileMode(0o700)
298
299 oid1 := oidForString(t, "k", "sdkjfn")
300 oid2 := oidForString(t, "k", "hvhjb")
301
302 dir1 := createTestDirectory(
303 "testDir1",
304 dirModTime,
305 dirOwnerInfo,
306 dirMode,
307 oid1,
308 &testFile{testBaseEntry: testBaseEntry{modtime: fileModTime1, name: "file1.txt", oid: oid1}, content: "abcdefghij"},
309 )
310 dir2 := createTestDirectory(
311 "testDir2",
312 dirModTime,
313 dirOwnerInfo,
314 dirMode,
315 oid2,
316 &testFile{testBaseEntry: testBaseEntry{modtime: fileModTime2, name: "file1.txt", oid: oid2}, content: "abcdefghij"},
317 )
318
319 c, err := diff.NewComparer(&buf, statsOnly)
320 require.NoError(t, err)
321
322 t.Cleanup(func() {
323 _ = c.Close()
324 })
325
326 expectedStats := diff.Stats{}
327 expectedStats.FileEntries.Modified = 1
328
329 expectedOutput := "./file1.txt modification times differ: 2023-04-12 10:30:00 +0000 UTC 2022-04-12 10:30:00 +0000 UTC\n"
330
331 actualStats, err := c.Compare(ctx, dir1, dir2)
332
333 require.NoError(t, err)
334 require.Equal(t, expectedOutput, buf.String())
335 require.Equal(t, expectedStats, actualStats)
336}
337
338func TestCompareFileWithIdenticalContentsButDiffFileMetadata(t *testing.T) {
339 var buf bytes.Buffer

Callers

nothing calls this directly

Calls 8

CloseMethod · 0.95
CompareMethod · 0.95
NewComparerFunction · 0.92
oidForStringFunction · 0.85
createTestDirectoryFunction · 0.85
EqualMethod · 0.80
CleanupMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected