diff options
Diffstat (limited to 'internal/engine/match_test.go')
| -rw-r--r-- | internal/engine/match_test.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/internal/engine/match_test.go b/internal/engine/match_test.go index 63bb54a..224f881 100644 --- a/internal/engine/match_test.go +++ b/internal/engine/match_test.go @@ -460,3 +460,37 @@ func TestRuleDuplicateWarningShortensThePath(t *testing.T) { t.Errorf("no shortened rule warning for a.txt: %+v %+v", r.Matched, r.Unmatched) } } + +// TestFileMatchNamesTheDuplicate: a file a (duplicate) test matched comes +// back with the other copy's absolute path, so a front end can say where it +// is and act on it - the reason text alone says "duplicate of NAME" for a +// copy inside the directory, which reads as no place at all (plan 21). +func TestFileMatchNamesTheDuplicate(t *testing.T) { + e, d, _ := fixture(t) + res, err := e.Match(context.Background(), d) + if err != nil { + t.Fatal(err) + } + found := false + for _, fm := range res.Matched { + if fm.File.Rel != "report (1).pdf" && fm.File.Rel != "report.pdf" { + continue + } + if fm.DuplicateOf == "" { + continue + } + found = true + if !filepath.IsAbs(fm.DuplicateOf) { + t.Errorf("%s: DuplicateOf = %q, want an absolute path", fm.File.Rel, fm.DuplicateOf) + } + if fm.DuplicateOf == fm.File.Path { + t.Errorf("%s: reported as a duplicate of itself", fm.File.Rel) + } + if _, err := os.Stat(fm.DuplicateOf); err != nil { + t.Errorf("%s: DuplicateOf does not exist: %v", fm.File.Rel, err) + } + } + if !found { + t.Fatal("neither copy came back with the file it duplicates") + } +} |
