Files
weatherapi/internal/platform/config/config_test.go
Eric Rakestraw 27817f9e43
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
Initial MVP commit
2026-03-17 08:35:16 -05:00

54 lines
1.2 KiB
Go

package config
import (
"os"
"path/filepath"
"testing"
)
func TestLoadRootList(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.yml")
content := `
- name: weatherdb
driver: postgres
params:
uri: postgres://weatherdb:5432/weatherdb?sslmode=disable
username: weatherdb
password: weatherdb
`
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
t.Fatalf("write temp config: %v", err)
}
cfg, err := Load(path)
if err != nil {
t.Fatalf("load config: %v", err)
}
if len(cfg.Databases) != 1 {
t.Fatalf("expected one database, got %d", len(cfg.Databases))
}
if cfg.Databases[0].Name != "weatherdb" {
t.Fatalf("unexpected db name %q", cfg.Databases[0].Name)
}
}
func TestLoadMissingRequiredFieldFails(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "config.yml")
content := `
- name: weatherdb
driver: postgres
params:
username: weatherdb
password: weatherdb
`
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
t.Fatalf("write temp config: %v", err)
}
if _, err := Load(path); err == nil {
t.Fatalf("expected validation error for missing params.uri")
}
}