Chore: tests update

This commit is contained in:
Grail Finder
2025-09-06 15:12:07 +03:00
parent c75ac433d4
commit ab8ec4c55a
3 changed files with 109 additions and 28 deletions

View File

@@ -10,25 +10,34 @@ import (
func TestDeepSeekParser_ParseBytes(t *testing.T) {
// Create a logger for testing
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
// Create a default config for testing
cfg := config.LoadConfigOrDefault("")
// Create a new deepSeekParser
parser := NewDeepSeekParser(logger, config.LoadConfigOrDefault("config.toml"))
parser := NewDeepSeekParser(logger, cfg)
// Test case 1: Regular text response
t.Run("RegularTextResponse", func(t *testing.T) {
// Mock response JSON for a regular text response
responseJSON := `{
"id": "test-id",
"object": "text.completion",
"object": "text_completion",
"created": 1234567890,
"model": "deepseek-chat",
"model": "deepseek/deepseek-chat-v3-0324:free",
"choices": [
{
"text": "This is a regular response",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
}
]
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 5,
"total_tokens": 15
}
}`
result, err := parser.ParseBytes([]byte(responseJSON))
@@ -49,7 +58,7 @@ func TestDeepSeekParser_ParseBytes(t *testing.T) {
"id": "test-id",
"object": "chat.completion",
"created": 1234567890,
"model": "deepseek-chat",
"model": "deepseek/deepseek-chat-v3-0324:free",
"choices": [
{
"index": 0,
@@ -90,7 +99,7 @@ func TestDeepSeekParser_ParseBytes(t *testing.T) {
"id": "test-id",
"object": "chat.completion",
"created": 1234567890,
"model": "deepseek-chat",
"model": "deepseek/deepseek-chat-v3-0324:free",
"choices": [
{
"index": 0,
@@ -118,25 +127,35 @@ func TestDeepSeekParser_ParseBytes(t *testing.T) {
func TestOpenRouterParser_ParseBytes(t *testing.T) {
// Create a logger for testing
logger := slog.New(slog.NewTextHandler(os.Stderr, nil))
// Create a default config for testing
cfg := config.LoadConfigOrDefault("")
// Create a new openRouterParser
parser := NewOpenRouterParser(logger, config.LoadConfigOrDefault("config.toml"))
// Test case 1: Regular text response
// Test case 1: Regular text response (completion API)
t.Run("RegularTextResponse", func(t *testing.T) {
// Create a new openRouterParser with completion API
parser := NewOpenRouterParser(logger, cfg)
parser.useChatAPI = false // Use completion API for this test
// Mock response JSON for a regular text response
responseJSON := `{
"id": "test-id",
"object": "text.completion",
"object": "text_completion",
"created": 1234567890,
"model": "deepseek-r1",
"model": "deepseek/deepseek-chat-v3-0324:free",
"choices": [
{
"text": "This is a regular response",
"index": 0,
"logprobs": null,
"finish_reason": "stop"
}
]
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 5,
"total_tokens": 15
}
}`
result, err := parser.ParseBytes([]byte(responseJSON))
@@ -150,14 +169,18 @@ func TestOpenRouterParser_ParseBytes(t *testing.T) {
}
})
// Test case 2: Tool call response
// Test case 2: Tool call response (chat API)
t.Run("ToolCallResponse", func(t *testing.T) {
// Create a new openRouterParser with chat API
parser := NewOpenRouterParser(logger, cfg)
parser.useChatAPI = true // Use chat API for this test
// Mock response JSON for a tool call response
responseJSON := `{
"id": "test-id",
"object": "chat.completion",
"created": 1234567890,
"model": "deepseek-r1",
"model": "deepseek/deepseek-chat-v3-0324:free",
"choices": [
{
"index": 0,
@@ -190,5 +213,4 @@ func TestOpenRouterParser_ParseBytes(t *testing.T) {
t.Errorf("Expected %s, got %s", expected, result)
}
})
}
}