2016-03-20 16:57:25 +01:00
|
|
|
package cmds
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadConfig(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
2016-03-27 17:03:14 +02:00
|
|
|
cmdData := &CmdData{}
|
|
|
|
|
2016-03-20 16:57:25 +01:00
|
|
|
file, _ := ioutil.TempFile(os.TempDir(), "sqlboilercfgtest")
|
|
|
|
defer os.Remove(file.Name())
|
|
|
|
|
|
|
|
fContents := `[postgres]
|
|
|
|
host="localhost"
|
|
|
|
port=5432
|
|
|
|
user="user"
|
|
|
|
pass="pass"
|
|
|
|
dbname="mydb"`
|
|
|
|
|
|
|
|
file.WriteString(fContents)
|
2016-03-27 17:03:14 +02:00
|
|
|
err := cmdData.LoadConfigFile(file.Name())
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to load config file: %s", err)
|
2016-03-20 16:57:25 +01:00
|
|
|
}
|
|
|
|
|
2016-03-27 17:03:14 +02:00
|
|
|
if cmdData.Config.Postgres.Host != "localhost" ||
|
|
|
|
cmdData.Config.Postgres.User != "user" || cmdData.Config.Postgres.Pass != "pass" ||
|
|
|
|
cmdData.Config.Postgres.DBName != "mydb" || cmdData.Config.Postgres.Port != 5432 {
|
|
|
|
t.Errorf("Config failed to load properly, got: %#v", cmdData.Config.Postgres)
|
2016-03-20 16:57:25 +01:00
|
|
|
}
|
|
|
|
}
|