package websearch import ( "testing" ) func TestNewDefaultEngine(t *testing.T) { tool := New(Config{}, 4000, nil) if tool.Name() != "web_search" { t.Fatalf("expected name web_search, got %s", tool.Name()) } if tool.engine != "duckduckgo" { t.Fatalf("expected default engine duckduckgo, got %s", tool.engine) } } func TestNewBraveEngine(t *testing.T) { tool := New(Config{Engine: "brave", APIKey: "test-key"}, 4000, nil) if tool.engine != "brave" { t.Fatalf("expected engine brave, got %s", tool.engine) } if tool.apiKey != "test-key" { t.Fatalf("expected apiKey test-key, got %s", tool.apiKey) } } func TestCallRejectsEmptyQuery(t *testing.T) { tool := New(Config{}, 4000, nil) _, err := tool.Call(nil, " ") if err == nil { t.Fatal("expected error for empty query") } } func TestFormatDuckDuckGoResultWithAnswer(t *testing.T) { tool := New(Config{}, 4000, nil) ddg := duckDuckGoResponse{ Answer: "42", AbstractText: "The answer to everything.", } result := tool.formatDuckDuckGoResult("meaning of life", ddg) if result == "" { t.Fatal("expected non-empty result") } if len(result) == 0 { t.Fatal("result should contain content") } } func TestFormatBraveResultEmpty(t *testing.T) { tool := New(Config{Engine: "brave"}, 4000, nil) resp := braveSearchResponse{} result := tool.formatBraveResult("test", resp) if result == "" { t.Fatal("expected non-empty result") } }