test: add unit tests for pkg/config package#199
test: add unit tests for pkg/config package#199mason5052 wants to merge 2 commits intovxcontrol:masterfrom
Conversation
Add comprehensive unit tests for NewConfig defaults, environment variable overrides, URL parsing, provider server URL defaults, summarizer defaults, search engine defaults, and ensureInstallationID logic including UUID generation, file persistence, and invalid value handling.
There was a problem hiding this comment.
Pull request overview
Adds initial unit test coverage for backend/pkg/config, focusing on NewConfig() default/env parsing behavior and ensureInstallationID() persistence/validation behavior.
Changes:
- Add unit tests for
NewConfig()defaults and selected env var overrides (URLs, provider defaults, summarizer/search defaults, CORS, Ollama). - Add unit tests for
ensureInstallationID()covering generation, reading existing IDs, and invalid-value replacement paths.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
backend/pkg/config/config_test.go
Outdated
| // Unset env vars that would override defaults | ||
| t.Setenv("DATABASE_URL", "") | ||
| t.Setenv("LICENSE_KEY", "") | ||
|
|
There was a problem hiding this comment.
These tests call NewConfig(), which reads environment variables (and godotenv.Load() may load a local .env) and also may read/write ./data/installation_id via ensureInstallationID(). Setting vars to "" does not actually unset them. To make the defaults tests hermetic and avoid side effects/flakes across dev/CI environments, consider (a) t.Chdir(t.TempDir()) before calling NewConfig() and/or (b) explicitly os.Unsetenv (with cleanup restore) for the env vars whose defaults you assert, rather than t.Setenv(key, "").
Add clearConfigEnv helper that clears all Config struct env vars via t.Setenv, and use t.Chdir(t.TempDir()) to isolate filesystem side effects from godotenv.Load() and ensureInstallationID(). Tests now pass regardless of environment variables set in the calling shell.
Description of Change
Problem: The
pkg/configpackage has no unit test coverage. This package handles all environment variable parsing, default values, URL parsing, and installation ID management for the entire application.Solution: Add 14 unit tests covering NewConfig defaults, environment variable overrides, URL parsing, provider server URL defaults, summarizer settings, search engine defaults, and all ensureInstallationID code paths (UUID generation, file read/write, invalid value handling).
Type of Change
Areas Affected
Testing and Verification
Test Configuration
Test Steps
go test ./pkg/config/... -vTest Results
Checklist
go fmtandgo vetrun