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) {
|
|
|
|
config.Create("../goploy.toml")
|
|
|
|
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-05-02 15:11:53 +08:00
|
|
|
if err := UserDB(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)
|
|
|
|
}
|
|
|
|
}
|