sqlboiler/cmds/templates_test/main.tpl
Patrick O'brien 48a9ba8d29 Added main template test file, fixed errors
* Fixed TestTemplates bug (now shows compile errors properly)
* Fixed all compile errors for templates (except test templates)
* Added conditional imports for column types
2016-03-23 13:08:35 +10:00

50 lines
1.1 KiB
Smarty

type PostgresCfg struct {
User string `toml:"user"`
Pass string `toml:"pass"`
Host string `toml:"host"`
Port int `toml:"port"`
DBName string `toml:"dbname"`
}
type Config struct {
Postgres PostgresCfg `toml:"postgres"`
TestPostgres *PostgresCfg `toml:"postgres_test"`
}
var cfg *Config
func LoadConfigFile(filename string) {
_, err := toml.DecodeFile(filename, &cfg)
if os.IsNotExist(err) {
fmt.Fatalf("Failed to find the toml configuration file %s: %s", filename, err)
}
if err != nil {
fmt.Fatalf("Failed to decode toml configuration file:", err)
}
if cfg.TestPostgres != nil {
if cfg.TestPostgres.User == "" || cfg.TestPostgres.Pass == "" ||
cfg.TestPostgres.Host == "" || cfg.TestPostgres.Port == 0 ||
cfg.TestPostgres.DBName == "" || cfg.Postgres.DBName == cfg.TestPostgres.DBName {
cfg.TestPostgres = nil
}
}
if cfg.TestPostgres == nil {
fmt.Fatalf("Failed to load config.toml postgres_test config")
}
}
func TestMain(m *testing.M) {
setup()
code := m.Run()
// shutdown
os.Exit(code)
}
func setup() {
LoadConfigFile("../config.toml")
}