package engines import ( "context" "net/http" "strings" "testing" "time" "github.com/metamorphosis-dev/kafka/internal/contracts" ) func TestDuckDuckGoEngine_EmptyQuery(t *testing.T) { eng := &DuckDuckGoEngine{} req := contracts.SearchRequest{Query: ""} resp, err := eng.Search(context.Background(), req) if err != nil { t.Fatalf("unexpected error: %v", err) } if len(resp.Results) != 0 { t.Errorf("expected 0 results for empty query, got %d", len(resp.Results)) } } func TestDuckDuckGoEngine_NilClient(t *testing.T) { eng := (*DuckDuckGoEngine)(nil) _, err := eng.Search(context.Background(), contracts.SearchRequest{Query: "test"}) if err == nil { t.Error("expected error for nil engine") } } func TestDuckDuckGoEngine_UninitializedClient(t *testing.T) { eng := &DuckDuckGoEngine{} _, err := eng.Search(context.Background(), contracts.SearchRequest{Query: "test"}) if err == nil { t.Error("expected error for uninitialized client") } } func TestDuckDuckGoEngine_Name(t *testing.T) { eng := &DuckDuckGoEngine{} if eng.Name() != "duckduckgo" { t.Errorf("expected 'duckduckgo', got %q", eng.Name()) } } func TestDuckDuckGoRegion(t *testing.T) { tests := []struct { lang string want string }{ {"", "us-en"}, {"auto", "us-en"}, {"en", "us-en"}, {"de", "de-de"}, {"fr", "fr-fr"}, {"en-US", "us-en"}, {"ja", "jp-jp"}, {"unknown", "wt-wt"}, } for _, tt := range tests { t.Run(tt.lang, func(t *testing.T) { got := duckduckgoRegion(tt.lang) if got != tt.want { t.Errorf("duckduckgoRegion(%q) = %q, want %q", tt.lang, got, tt.want) } }) } } func TestParseDuckDuckGoHTML(t *testing.T) { html := `Example Title