goploy/model/model_test.go

31 lines
615 B
Go
Raw Normal View History

2022-05-02 15:11:53 +08:00
package model
2022-04-11 11:08:45 +08:00
import (
"database/sql"
"fmt"
"github.com/zhenorzz/goploy/config"
"testing"
)
func TestInitDB(t *testing.T) {
2022-12-08 14:02:22 +08:00
config.InitToml()
2022-04-11 11:08:45 +08:00
db, err := sql.Open(config.Toml.DB.Type, fmt.Sprintf(
"%s:%s@(%s:%s)/?charset=utf8mb4,utf8\n",
config.Toml.DB.User,
config.Toml.DB.Password,
config.Toml.DB.Host,
config.Toml.DB.Port))
if err != nil {
t.Fatal(err)
}
2022-05-02 15:11:53 +08:00
if err := CreateDB(db, config.Toml.DB.Database); err != nil {
2022-04-11 11:08:45 +08:00
t.Fatal(err)
}
2022-11-23 10:30:02 +08:00
if err := UseDB(db, config.Toml.DB.Database); err != nil {
2022-04-11 11:08:45 +08:00
t.Fatal(err)
}
2022-05-02 15:11:53 +08:00
if err := ImportSQL(db, "sql/goploy.sql"); err != nil {
2022-04-11 11:08:45 +08:00
t.Fatal(err)
}
}