All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
54 lines
1.2 KiB
Go
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")
|
|
}
|
|
}
|