samsa/internal/engines/github_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

72 lines
1.7 KiB
Go

package engines
import (
"context"
"net/http"
"testing"
"time"
"github.com/metamorphosis-dev/samsa/internal/contracts"
)
func TestGitHubEngine_EmptyQuery(t *testing.T) {
eng := &GitHubEngine{}
resp, err := eng.Search(context.Background(), contracts.SearchRequest{Query: ""})
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 TestGitHubEngine_Name(t *testing.T) {
eng := &GitHubEngine{}
if eng.Name() != "github" {
t.Errorf("expected 'github', got %q", eng.Name())
}
}
func TestGitHubEngine_Uninitialized(t *testing.T) {
eng := &GitHubEngine{}
_, err := eng.Search(context.Background(), contracts.SearchRequest{Query: "test"})
if err == nil {
t.Error("expected error for uninitialized client")
}
}
func TestGitHubEngine_LiveRequest(t *testing.T) {
if testing.Short() {
t.Skip("skipping live request")
}
client := &http.Client{}
eng := &GitHubEngine{client: client}
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
resp, err := eng.Search(ctx, contracts.SearchRequest{
Query: "golang cli",
})
if err != nil {
t.Fatalf("live search failed: %v", err)
}
if resp.NumberOfResults <= 0 {
t.Error("expected some results for 'golang cli'")
}
if len(resp.Results) == 0 {
t.Error("expected at least 1 result")
}
// Verify structure.
for _, r := range resp.Results {
if r.Engine != "github" {
t.Errorf("expected engine 'github', got %q", r.Engine)
}
if r.URL == nil || *r.URL == "" {
t.Error("expected non-empty URL")
}
}
t.Logf("github returned %d results (total: %d)", len(resp.Results), resp.NumberOfResults)
}