Files
slinky/internal/fsurls/fsurls_test.go
Luke Hagar 54d7797089 Add .slinkignore support for URL and path exclusions
Introduce a new .slinkignore file format to allow users to specify paths and URLs to ignore during scanning. Update the CollectURLs and CollectURLsProgress functions to respect these ignore rules. Add tests to verify the functionality of the .slinkignore file, ensuring that specified paths and URLs are excluded from results. Update README.md to document the new feature and its usage.
2025-09-12 20:56:45 +00:00

57 lines
1.5 KiB
Go

package fsurls
import (
"path/filepath"
"strings"
"testing"
)
func TestCollectURLs_FromTestFiles(t *testing.T) {
root := filepath.Join("..", "..", "testdata")
urls, err := CollectURLs(root, []string{"**/*"}, true)
if err != nil {
t.Fatalf("CollectURLs error: %v", err)
}
// Spot-check presence of some known URLs
mustContain := []string{
"https://example.com",
"https://en.wikipedia.org/wiki/Main_Page",
"http://example.com:8080",
"https://this-domain-does-not-exist-123456789.com",
}
for _, u := range mustContain {
if _, ok := urls[u]; !ok {
// Show nearby URLs to aid debugging if it fails.
var sample []string
for seen := range urls {
if strings.Contains(seen, "example") {
sample = append(sample, seen)
}
}
t.Fatalf("expected URL %q to be collected; example URLs seen: %v", u, sample)
}
}
// Ensure sources are recorded for a known URL
srcs := urls["https://example.com"]
if len(srcs) == 0 {
t.Fatalf("expected sources for https://example.com, got none")
}
// Verify .slinkignore URL ignores
if _, ok := urls["https://example.com/this/path/does/not/exist"]; ok {
t.Fatalf("expected URL ignored by .slinkignore to be absent")
}
// Verify .slinkignore path ignores: file under ignore-me should not contribute
for u, files := range urls {
for _, f := range files {
if strings.Contains(f, "ignore-me/") {
t.Fatalf("file %s should have been ignored via .slinkignore, but contributed to URL %s", f, u)
}
}
}
}