aboutsummaryrefslogtreecommitdiff
path: root/internal/dup/dup_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/dup/dup_test.go')
-rw-r--r--internal/dup/dup_test.go23
1 files changed, 23 insertions, 0 deletions
diff --git a/internal/dup/dup_test.go b/internal/dup/dup_test.go
index fb4e64d..5d2621c 100644
--- a/internal/dup/dup_test.go
+++ b/internal/dup/dup_test.go
@@ -262,6 +262,29 @@ func TestLookupFailsWhenSubjectUnreadable(t *testing.T) {
}
}
+// TestSameContentEqualSizeDifferentContent: two files of identical size but
+// different bytes must not be reported as the same content — the partial
+// hash (not just the size check) has to separate them.
+func TestSameContentEqualSizeDifferentContent(t *testing.T) {
+ d := t.TempDir()
+ a := filepath.Join(d, "a.bin")
+ b := filepath.Join(d, "b.bin")
+ one := []byte("acme-invoice-01")
+ two := []byte("acme-invoice-02")
+ if len(one) != len(two) {
+ t.Fatal("fixture bug: files must be the same size")
+ }
+ if err := os.WriteFile(a, one, 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(b, two, 0o644); err != nil {
+ t.Fatal(err)
+ }
+ if ok, err := SameContent(a, b); err != nil || ok {
+ t.Errorf("SameContent(a, b) = %v, %v; want false, nil", ok, err)
+ }
+}
+
// fakeDirEntry is an fs.DirEntry whose Info() returns a canned result, for
// exercising addEntry's Info()-failure handling directly (A3) — a real
// filepath.WalkDir gives no hook to inject a stat failure deterministically