diff --git a/internal/config/config_test.go b/internal/config/config_test.go new file mode 100644 index 0000000..90b721f --- /dev/null +++ b/internal/config/config_test.go @@ -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) + } +}