forked from go-gorm/gen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: update unit test github workflow
test: add test config test: add test steps for mysql test: update go version test: remove verbose test test: fix dsn tests: fix dsn tests: add test case
- Loading branch information
Showing
9 changed files
with
169 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
go.sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Test Guide | ||
|
||
```bash | ||
cd tests | ||
# prepare test databases | ||
docker-compose up | ||
|
||
# run all tests | ||
./tests_all.sh | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: '3' | ||
|
||
services: | ||
mysql: | ||
image: 'mysql/mysql-server:latest' | ||
ports: | ||
- 9910:3306 | ||
environment: | ||
- MYSQL_DATABASE=gen | ||
- MYSQL_USER=gen | ||
- MYSQL_PASSWORD=gen | ||
- MYSQL_RANDOM_ROOT_PASSWORD="yes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module gorm.io/gen/tests | ||
|
||
go 1.16 | ||
|
||
require ( | ||
gorm.io/driver/mysql v1.3.6 | ||
gorm.io/gorm v1.23.8 | ||
) | ||
|
||
replace gorm.io/gen => ../ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/bin/bash -e | ||
|
||
# dialects=("sqlite" "mysql" "postgres" "sqlserver") | ||
dialects=("mysql") | ||
|
||
if [[ $(pwd) == *"gen/tests"* ]]; then | ||
cd .. | ||
fi | ||
|
||
if [ -d tests ] | ||
then | ||
cd tests | ||
go get -u -t ./... | ||
go mod download | ||
go mod tidy | ||
cd .. | ||
fi | ||
|
||
# SqlServer for Mac M1 | ||
if [[ -z $GITHUB_ACTION ]]; then | ||
if [ -d tests ] | ||
then | ||
cd tests | ||
if [[ $(uname -a) == *" arm64" ]]; then | ||
MSSQL_IMAGE=mcr.microsoft.com/azure-sql-edge docker-compose start || true | ||
go install github.com/microsoft/go-sqlcmd/cmd/sqlcmd@latest || true | ||
SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF DB_ID('gen') IS NULL CREATE DATABASE gen" > /dev/null || true | ||
SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF SUSER_ID (N'gen') IS NULL CREATE LOGIN gen WITH PASSWORD = 'LoremIpsum86';" > /dev/null || true | ||
SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF USER_ID (N'gen') IS NULL CREATE USER gen FROM LOGIN gen; ALTER SERVER ROLE sysadmin ADD MEMBER [gen];" > /dev/null || true | ||
else | ||
docker-compose start | ||
fi | ||
cd .. | ||
fi | ||
fi | ||
|
||
for dialect in "${dialects[@]}" ; do | ||
if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ] | ||
then | ||
echo "testing ${dialect}..." | ||
|
||
if [ "$GEN_VERBOSE" = "" ] | ||
then | ||
if [ -d tests ] | ||
then | ||
cd tests | ||
GORM_DIALECT=${dialect} go test -race -count=1 ./... | ||
cd .. | ||
fi | ||
else | ||
if [ -d tests ] | ||
then | ||
cd tests | ||
GORM_DIALECT=${dialect} go test -race -count=1 -v ./... | ||
cd .. | ||
fi | ||
fi | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package tests_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"gorm.io/driver/mysql" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func init() { | ||
dsn := os.Getenv("GORM_DSN") | ||
if dsn == "" { | ||
dsn = "gen:gen@tcp(localhost:9910)/gen?charset=utf8&parseTime=True&loc=Local" | ||
} | ||
|
||
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{}) | ||
if err != nil { | ||
panic(fmt.Errorf("open mysql fail: %w", err)) | ||
} | ||
_ = db | ||
} |