mirror of
https://gitee.com/goploy/goploy.git
synced 2024-12-02 04:07:33 +08:00
32 lines
656 B
Go
32 lines
656 B
Go
package model
|
|
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
"github.com/zhenorzz/goploy/config"
|
|
"github.com/zhenorzz/goploy/database"
|
|
"testing"
|
|
)
|
|
|
|
func TestInitDB(t *testing.T) {
|
|
config.InitToml()
|
|
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)
|
|
}
|
|
if err := CreateDB(db, config.Toml.DB.Database); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := UseDB(db, config.Toml.DB.Database); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := ImportSQL(db, database.GoploySQL); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|