samsa/internal/search/merge_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

80 lines
2.2 KiB
Go

package search
import (
"strings"
"testing"
"github.com/metamorphosis-dev/samsa/internal/contracts"
)
func TestMergeResponses_DedupResultsAndSets(t *testing.T) {
url1 := "https://example.com/a?x=1"
uPtr := &url1
r1 := contracts.SearchResponse{
Query: "q",
NumberOfResults: 1,
Results: []contracts.MainResult{
{
Template: "default.html",
Title: "Title1",
Content: "C1",
URL: uPtr,
Engine: "wikipedia",
Score: 1.0,
},
},
Answers: []map[string]any{{"title": "A1", "url": url1}},
Corrections: []string{"corr1", "corr2"},
Suggestions: []string{"s1", "s2"},
Infoboxes: []map[string]any{},
UnresponsiveEngines: [][2]string{},
}
r2 := contracts.SearchResponse{
Query: "q",
NumberOfResults: 1,
Results: []contracts.MainResult{
{
Template: "default.html",
Title: "Title1",
Content: "C2",
URL: uPtr,
Engine: "wikipedia",
Score: 2.0,
},
},
Answers: []map[string]any{{"title": "A1", "url": url1}},
Corrections: []string{"corr2", "corr3"},
Suggestions: []string{"s2", "s3"},
Infoboxes: []map[string]any{},
UnresponsiveEngines: [][2]string{},
}
merged := MergeResponses([]contracts.SearchResponse{r1, r2})
if merged.Query != "q" {
t.Fatalf("expected query q, got %q", merged.Query)
}
if merged.NumberOfResults != 1 {
t.Fatalf("expected number_of_results max=1, got %d", merged.NumberOfResults)
}
if len(merged.Results) != 1 {
t.Fatalf("expected 1 merged result, got %d", len(merged.Results))
}
// Corrections/suggestions should be unioned.
joinedCorr := strings.Join(merged.Corrections, ",")
if !strings.Contains(joinedCorr, "corr1") || !strings.Contains(joinedCorr, "corr2") || !strings.Contains(joinedCorr, "corr3") {
t.Fatalf("expected unioned corrections, got %v", merged.Corrections)
}
joinedSug := strings.Join(merged.Suggestions, ",")
if !strings.Contains(joinedSug, "s1") || !strings.Contains(joinedSug, "s2") || !strings.Contains(joinedSug, "s3") {
t.Fatalf("expected unioned suggestions, got %v", merged.Suggestions)
}
if len(merged.Answers) != 1 {
t.Fatalf("expected 1 merged answer, got %d", len(merged.Answers))
}
}