samsa/internal/engines/wikipedia_test.go
Franz Kafka 8e9aae062b
Some checks failed
Build and Push Docker Image / build-and-push (push) Failing after 11s
Mirror to GitHub / mirror (push) Failing after 5s
Tests / test (push) Successful in 42s
rename: kafka → samsa
Full project rename from kafka to samsa (after Gregor Samsa, who
woke one morning from uneasy dreams to find himself transformed).

- Module: github.com/metamorphosis-dev/kafka → samsa
- Binary: cmd/kafka/ → cmd/samsa/
- CSS: kafka.css → samsa.css
- UI: all 'kafka' product names, titles, localStorage keys → samsa
- localStorage keys: kafka-theme → samsa-theme, kafka-engines → samsa-engines
- OpenSearch: ShortName, LongName, description, URLs updated
- AGPL headers: 'kafka' → 'samsa'
- Docs, configs, examples updated
- Cache key prefix: kafka: → samsa:
2026-03-22 23:44:55 +00:00

61 lines
1.5 KiB
Go

package engines
import (
"context"
"net/http"
"testing"
"github.com/metamorphosis-dev/samsa/internal/contracts"
)
func TestWikipediaEngine_Search(t *testing.T) {
transport := roundTripperFunc(func(r *http.Request) (*http.Response, error) {
if r.Method != http.MethodGet {
return httpResponse(http.StatusMethodNotAllowed, "", ""), nil
}
if r.URL.Host != "en.wikipedia.org" {
return httpResponse(http.StatusNotFound, "", ""), nil
}
if r.URL.Path != "/api/rest_v1/page/summary/Taxi" {
return httpResponse(http.StatusNotFound, "", ""), nil
}
body := `{
"title": "Taxi",
"description": "A car",
"titles": { "display": "Taxi" },
"content_urls": { "desktop": { "page": "https://en.wikipedia.org/wiki/Taxi" } }
}`
return httpResponse(http.StatusOK, body, "application/json"), nil
})
client := &http.Client{Transport: transport}
engine := &WikipediaEngine{client: client}
resp, err := engine.Search(context.Background(), contracts.SearchRequest{
Query: "Taxi",
Pageno: 1,
Language: "en",
})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if len(resp.Results) != 1 {
t.Fatalf("expected 1 result, got %d", len(resp.Results))
}
r := resp.Results[0]
if r.Title != "Taxi" {
t.Fatalf("expected title Taxi, got %q", r.Title)
}
if r.Content != "A car" {
t.Fatalf("expected content, got %q", r.Content)
}
if r.URL == nil || *r.URL == "" {
t.Fatalf("expected url, got nil/empty")
}
if *r.URL != "https://en.wikipedia.org/wiki/Taxi" {
t.Fatalf("unexpected url: %q", *r.URL)
}
}