初始化提交

This commit is contained in:
chenxin committed 2026-08-21 16:00:13 +08:00
commit 887c1f449e
963 files changed
+166869

No files matched your search

@@ -0,0 +1,53 @@
package providers
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/chenxin/hunjing/mcp/web-search/internal/models"
)
func TestBraveProvider_Search_Success(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Header.Get("X-Subscription-Token") == "" {
t.Error("missing subscription token header")
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`{
"web": {
"results": [
{"title": "Brave Result", "url": "https://brave.com/1", "description": "Brave snippet"}
]
}
}`))
}))
defer ts.Close()
p := &BraveProvider{
client: ts.Client(),
apiBase: ts.URL,
maxResults: 10,
}
r, err := p.Search(context.Background(), "test-key", &models.SearchRequest{Query: "test"})
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if r.TotalCount != 1 {
t.Fatalf("expected 1 result, got %d", r.TotalCount)
}
if r.Results[0].Title != "Brave Result" {
t.Errorf("expected 'Brave Result', got '%s'", r.Results[0].Title)
}
}
func TestBraveProvider_Name(t *testing.T) {
p := NewBraveProvider(5*time.Second, 10)
if p.Name() != models.ProviderBrave {
t.Errorf("expected brave, got %s", p.Name())
}
}