all repos — llm_aggregator @ 29a4710e981512a82abba77ec8d7b43e413453e7

A CLI tool to aggregate RSS feeds and summarise them with LLMs

internal/llm/llm_test.go (view raw)

 1package llm
 2
 3import (
 4	"strings"
 5	"testing"
 6)
 7
 8func TestNewLLMClientTimeout(t *testing.T) {
 9	tests := []struct {
10		name          string
11		timeout       int
12		expectTimeout int
13	}{
14		{
15			name:          "zero timeout uses default 300",
16			timeout:       0,
17			expectTimeout: 300,
18		},
19		{
20			name:          "custom timeout is stored",
21			timeout:       60,
22			expectTimeout: 60,
23		},
24		{
25			name:          "large timeout is stored",
26			timeout:       600,
27			expectTimeout: 600,
28		},
29	}
30
31	for _, tt := range tests {
32		t.Run(tt.name, func(t *testing.T) {
33			// API key is required; use a placeholder
34			client, err := NewLLMClient(
35				"test-api-key",
36				"",
37				"",
38				0,
39				0,
40				tt.timeout,
41			)
42			if err != nil {
43				t.Fatalf("NewLLMClient returned unexpected error: %v", err)
44			}
45			if client.llmTimeout != tt.expectTimeout {
46				t.Errorf("llmTimeout = %d, want %d", client.llmTimeout, tt.expectTimeout)
47			}
48		})
49	}
50}
51
52func TestNewLLMClientDefaults(t *testing.T) {
53	// Verify all defaults are applied when only API key is provided
54	client, err := NewLLMClient("test-api-key", "", "", 0, 0, 0)
55	if err != nil {
56		t.Fatalf("NewLLMClient returned unexpected error: %v", err)
57	}
58
59	if client.model != "deepseek-chat" {
60		t.Errorf("model = %q, want %q", client.model, "deepseek-chat")
61	}
62	if client.maxTokens != 4000 {
63		t.Errorf("maxTokens = %d, want %d", client.maxTokens, 4000)
64	}
65	if client.temperature != 0.7 {
66		t.Errorf("temperature = %f, want %f", client.temperature, 0.7)
67	}
68	if client.llmTimeout != 300 {
69		t.Errorf("llmTimeout = %d, want %d", client.llmTimeout, 300)
70	}
71}
72
73func TestNewLLMClientRequiresAPIKey(t *testing.T) {
74	_, err := NewLLMClient("", "", "", 0, 0, 0)
75	if err == nil {
76		t.Error("NewLLMClient expected error for missing API key, got nil")
77	}
78	if !strings.Contains(err.Error(), "API key is required") {
79		t.Errorf("error message = %q, want to contain %q", err.Error(), "API key is required")
80	}
81}