test: add unit tests for config loader
This commit is contained in:
parent
c554bf54af
commit
11fda03dbd
1 changed files with 44 additions and 0 deletions
44
internal/config/config_test.go
Normal file
44
internal/config/config_test.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLoadConfig_NotFound(t *testing.T) {
|
||||
_, err := Load("non_existent_config_file_12345.json")
|
||||
if err == nil {
|
||||
t.Fatal("expected error when loading non-existent config, got nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadConfig_ValidJSON(t *testing.T) {
|
||||
tmpDir := t.TempDir()
|
||||
tmpFile := filepath.Join(tmpDir, "config.json")
|
||||
|
||||
content := []byte(`{
|
||||
"telegram_token": "test_token",
|
||||
"gemini_api_key": "test_key",
|
||||
"gemini_base_url": "http://localhost:8080"
|
||||
}`)
|
||||
|
||||
if err := os.WriteFile(tmpFile, content, 0644); err != nil {
|
||||
t.Fatalf("failed to write temp config file: %v", err)
|
||||
}
|
||||
|
||||
cfg, err := Load(tmpFile)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to load valid config: %v", err)
|
||||
}
|
||||
|
||||
if cfg.TelegramToken != "test_token" {
|
||||
t.Errorf("expected telegram_token 'test_token', got '%s'", cfg.TelegramToken)
|
||||
}
|
||||
if cfg.GeminiApiKey != "test_key" {
|
||||
t.Errorf("expected gemini_api_key 'test_key', got '%s'", cfg.GeminiApiKey)
|
||||
}
|
||||
if cfg.GeminiBaseURL != "http://localhost:8080" {
|
||||
t.Errorf("expected gemini_base_url 'http://localhost:8080', got '%s'", cfg.GeminiBaseURL)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue