orchard
mirrorEvery site I host, in one repo, along with the Cloudflare Tunnel and Caddy that front them. It's all Go, Vite, and SQLite, and it runs on a desktop at home with nothing listening on an inbound port.
blogbuncaddycloudflare-tunneldockergogolanghomelabhtml-templatemonorepoself-hostedseosqlitestatic-sitetypstuptime-monitoringviteweb-analytics
1package main
2
3import (
4 neturl "net/url"
5 "testing"
6)
7
8func neturlParse(s string) (*neturl.URL, error) { return neturl.Parse(s) }
9
10func TestRankCandidates(t *testing.T) {
11 links := []Link{
12 {URL: "https://ollama.com/", Text: "Ollama"},
13 {URL: "https://example.com/blog/best-tools", Text: "read more"},
14 {URL: "https://github.com/ollama/ollama", Text: "the repo"},
15 {URL: "https://facebook.com/share", Text: "Ollama"},
16 }
17 got := rankCandidates("Ollama", links)
18 if len(got) == 0 {
19 t.Fatal("no candidates for a name that is right there")
20 }
21 if got[0].URL != "https://ollama.com/" {
22 t.Errorf("the name as the domain should win, got %s", got[0].URL)
23 }
24 for _, c := range got {
25 if c.URL == "https://example.com/blog/best-tools" {
26 t.Error("an unrelated link scored")
27 }
28 }
29 if len(rankCandidates("Deepest River", links)) != 0 {
30 t.Error("a name nothing links to should produce no candidates")
31 }
32}
33
34func TestKeepLinkDropsJunk(t *testing.T) {
35 base, _ := neturlParse("https://example.com/post")
36 cases := []struct {
37 href string
38 text string
39 keep bool
40 }{
41 {"https://ollama.com", "Ollama", true},
42 {"https://example.com/other", "same site", false},
43 {"https://facebook.com/sharer", "Share", false},
44 {"https://ollama.com", "x", false},
45 {"mailto:[email protected]", "mail", false},
46 }
47 for _, c := range cases {
48 u, err := neturlParse(c.href)
49 if err != nil {
50 t.Fatal(err)
51 }
52 if got := keepLink(u, base, c.text); got != c.keep {
53 t.Errorf("keepLink(%q, %q) = %v, want %v", c.href, c.text, got, c.keep)
54 }
55 }
56}