Fix tests script

This commit is contained in:
Jinzhu 2020-06-02 00:24:16 +08:00
parent 9807fffdbc
commit bc01eb28ad
4 changed files with 15 additions and 6 deletions

View File

@ -6,6 +6,11 @@ import (
. "github.com/jinzhu/gorm/tests"
)
func TestMain(m *testing.M) {
RunMigrations()
m.Run()
}
func TestExceptionsWithInvalidSql(t *testing.T) {
var columns []string
if DB.Where("sdsd.zaaa = ?", "sd;;;aa").Pluck("aaa", &columns).Error == nil {

View File

@ -25,7 +25,7 @@ func TestMigrate(t *testing.T) {
for _, m := range allModels {
if !DB.Migrator().HasTable(m) {
t.Fatalf("Failed to create table for %#v", m)
t.Fatalf("Failed to create table for %#v---", m)
}
}
}

View File

@ -19,9 +19,7 @@ var DB *gorm.DB
func init() {
var err error
if DB, err = OpenTestConnection(); err == nil {
RunMigrations()
} else {
if DB, err = OpenTestConnection(); err != nil {
log.Printf("failed to connect database, got error %v\n", err)
os.Exit(1)
}

View File

@ -9,11 +9,17 @@ for dialect in "${dialects[@]}" ; do
then
echo "testing ${dialect}..."
race=""
if [ "$GORM_VERBOSE" = "" ]
then
DEBUG=false GORM_DIALECT=${dialect} go test -race -count=1 ./...
race="-race"
fi
if [ "$GORM_VERBOSE" = "" ]
then
DEBUG=false GORM_DIALECT=${dialect} go test $race -count=1 ./...
else
DEBUG=false GORM_DIALECT=${dialect} go test -race -count=1 -v ./...
DEBUG=false GORM_DIALECT=${dialect} go test $race -count=1 -v ./...
fi
fi
done