github.com/team-ide/go-dialect@v1.9.20/test/mysql_test.go (about)

     1  package test
     2  
     3  import (
     4  	"database/sql"
     5  	"github.com/team-ide/go-dialect/dialect"
     6  	"github.com/team-ide/go-driver/db_mysql"
     7  	"testing"
     8  )
     9  
    10  var (
    11  	MysqlDb      *sql.DB
    12  	MysqlDialect dialect.Dialect
    13  )
    14  
    15  func initMysql() {
    16  	if MysqlDb != nil {
    17  		return
    18  	}
    19  	dsn := db_mysql.GetDSN("root", "123456", "localhost", 3306, "")
    20  	var err error
    21  	MysqlDb, err = db_mysql.Open(dsn)
    22  	if err != nil {
    23  		panic(err)
    24  	}
    25  	MysqlDialect, err = dialect.NewDialect(dialect.TypeMysql.Name)
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  	return
    30  }
    31  
    32  func TestMysqlLoad(t *testing.T) {
    33  	initMysql()
    34  	owners(MysqlDb, MysqlDialect)
    35  }
    36  
    37  func TestMysqlDDL(t *testing.T) {
    38  	initMysql()
    39  	owner := &dialect.OwnerModel{
    40  		OwnerName: "TEST_DB",
    41  	}
    42  	testOwnerDelete(MysqlDb, MysqlDialect, owner.OwnerName)
    43  	testOwnerCreate(MysqlDb, MysqlDialect, owner)
    44  
    45  	testDLL(MysqlDb, MysqlDialect, owner.OwnerName)
    46  }
    47  
    48  func TestMysqlSql(t *testing.T) {
    49  	initMysql()
    50  	sqlInfo := loadSql("sql_mysql.sql")
    51  	owner := &dialect.OwnerModel{
    52  		OwnerName: "TEST_DB",
    53  	}
    54  	testOwnerDelete(MysqlDb, MysqlDialect, owner.OwnerName)
    55  	testOwnerCreate(MysqlDb, MysqlDialect, owner)
    56  	sqlInfo = "use " + owner.OwnerName + ";\n" + sqlInfo
    57  
    58  	testSql(MysqlDb, MysqlDialect, owner.OwnerName, sqlInfo)
    59  }