| 15 | ) |
| 16 | |
| 17 | func TestGetDB(t *testing.T) { |
| 18 | err := config.Init(configs.Path("serverNameExample.yml")) |
| 19 | if err != nil { |
| 20 | panic(err) |
| 21 | } |
| 22 | |
| 23 | config.Get().App.EnableTrace = true |
| 24 | config.Get().Database.Mysql.EnableLog = true |
| 25 | |
| 26 | time.Sleep(time.Millisecond * 10) |
| 27 | err = CloseDB() |
| 28 | assert.NoError(t, err) |
| 29 | |
| 30 | utils.SafeRunWithTimeout(time.Second*2, func(cancel context.CancelFunc) { |
| 31 | db := GetDB() |
| 32 | assert.NotNil(t, db) |
| 33 | cancel() |
| 34 | }) |
| 35 | } |
| 36 | |
| 37 | func TestInitMysqlError(t *testing.T) { |
| 38 | err := config.Init(configs.Path("serverNameExample.yml")) |