package main
import "testing"
func TestDatabaseDefaultAndOverride(t *testing.T) {
for _, profile := range []string{"production", "compat"} {
for _, database := range []string{"", "dbname=custom host=localhost", "postgres://localhost/custom"} {
config, err := loadConfig(func(key string) string {
return map[string]string{"APP_PROFILE": profile, "ALLOWED_HOSTS": "localhost", "DATABASE_URL": database}[key]
})
if err != nil {
t.Fatal(err)
}
want := database
if want == "" {
want = "dbname=assignment_harness_native"
}
if config.Database != want {
t.Errorf("%s database = %q, want %q", profile, config.Database, want)
}
// The migrator uses the same connection resolution without server-only settings.
if databaseURL(database) != want {
t.Errorf("migration database differs for %q", database)
}
}
}
}