dtm/common/types_test.go
2021-06-03 17:56:09 +08:00

41 lines
738 B
Go

package common
import (
"testing"
"github.com/go-playground/assert/v2"
)
type testConfig struct {
Mysql map[string]string
}
var config = testConfig{}
var myinit int = func() int {
InitApp(GetProjectPath(), &config)
config.Mysql["database"] = "dtm"
return 0
}()
func TestDb(t *testing.T) {
db := DbGet(config.Mysql)
err := func() (rerr error) {
defer P2E(&rerr)
dbr := db.NoMust().Exec("select a")
assert.NotEqual(t, nil, dbr.Error)
db.Must().Exec("select a")
return nil
}()
assert.NotEqual(t, nil, err)
}
func TestDbAlone(t *testing.T) {
db, con := DbAlone(config.Mysql)
dbr := db.Exec("select 1")
assert.Equal(t, nil, dbr.Error)
con.Close()
dbr = db.Exec("select 1")
assert.NotEqual(t, nil, dbr.Error)
}