package linkcheck import ( "reflect" "testing" "github.com/axllent/mailpit/internal/storage" ) var ( testHTML = `

HTTP link

HTTPS link

HTTPS link

Localhost link (ignored)

Localhost link (ignored)

Single quotes link (ignored)

This should be ignored

Link with spaces

URL-encoded characters

` expectedHTMLLinks = []string{ "http://example.com", "https://example.com", "HTTPS://EXAMPLE.COM", "http://localhost", "https://localhost", "https://127.0.0.1", "http://link with spaces", "http://example.com/?blaah=yes&test=true", "http://remote-host/style.css", // css "https://example.com/image.jpg", // images } testTextLinks = `This is a line with http://example.com https://example.com HTTPS://EXAMPLE.COM [http://localhost] www.google.com < ignored |||http://example.com/?some=query-string||| ` expectedTextLinks = []string{ "http://example.com", "https://example.com", "HTTPS://EXAMPLE.COM", "http://localhost", "http://example.com/?some=query-string", } ) func TestLinkDetection(t *testing.T) { t.Log("Testing HTML link detection") m := storage.Message{} m.Text = testTextLinks m.HTML = testHTML textLinks := extractTextLinks(&m) if !reflect.DeepEqual(textLinks, expectedTextLinks) { t.Fatalf("Failed to detect text links correctly") } htmlLinks := extractHTMLLinks(&m) if !reflect.DeepEqual(htmlLinks, expectedHTMLLinks) { t.Fatalf("Failed to detect HTML links correctly") } }