package main import "testing" func TestPickPagesPrefersDocsAndOnePerSite(t *testing.T) { hits := []searchHit{ {URL: "https://blog.example.com/example-server"}, {URL: "https://github.com/a/example-docker"}, {URL: "https://github.com/b/other"}, {URL: "https://hub.docker.com/r/x/example"}, {URL: "https://blog.example.com/example-server"}, } got := pickPages(hits, 3) if len(got) != 3 { t.Fatalf("got %d pages", len(got)) } if got[0].URL != "https://github.com/a/example-docker" || got[1].URL != "https://hub.docker.com/r/x/example" || got[2].URL != "https://blog.example.com/example-server" { t.Errorf("order: %v", got) } } func TestTrimToJSON(t *testing.T) { if got := trimToJSON("Here you go:\n```json\n{\"a\": 1}\n```"); got != `{"a": 1}` { t.Errorf("got %q", got) } } func TestAppNameFromAppInfo(t *testing.T) { out := `"1000000" { "common" { "name" "Example Dedicated Server" "type" "Tool" } }` m := appName.FindStringSubmatch(out) if m == nil || m[1] != "Example Dedicated Server" { t.Errorf("got %v", m) } }