Initial MVP commit
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
53
internal/platform/config/config_test.go
Normal file
53
internal/platform/config/config_test.go
Normal file
@@ -0,0 +1,53 @@
|
||||
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")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user