From 70ec454f6448077a34a2d8ce11ce3cbffda5ba68 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 9 Oct 2022 16:10:24 +0800 Subject: [PATCH] Update test script, close #494 --- README.md | 10 +++------- docker-compose.yml | 5 ++--- go.mod | 13 ++++++------- test.sh | 17 ++++++++++++++++- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 3834e58..5ba5bbe 100644 --- a/README.md +++ b/README.md @@ -10,18 +10,14 @@ GORM Playground can be used to play GORM and reports issues, if you encounter a ##### 2. [Clone the forked repo to your local](https://docs.github.com/en/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/cloning-a-repository) -##### 3. Setup test database +##### 3. Install docker-compose -```bash -# install docker-compose https://docs.docker.com/compose/install/ - -# setup test databases -docker-compose up -``` +https://docs.docker.com/compose/install/ ##### 4. Run tests with lastest GORM and all drivers ```bash +# run tests (retry if failed due to preparing the testing database) ./test.sh # Run tests with cached GORM and latest drivers diff --git a/docker-compose.yml b/docker-compose.yml index 91a5f31..9ab4ddb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: '3' services: mysql: - image: 'mysql:latest' + image: 'mysql/mysql-server:latest' ports: - 9910:3306 environment: @@ -20,7 +20,7 @@ services: - POSTGRES_USER=gorm - POSTGRES_PASSWORD=gorm mssql: - image: 'mcmoe/mssqldocker:latest' + image: '${MSSQL_IMAGE:-mcmoe/mssqldocker}:latest' ports: - 9930:1433 environment: @@ -29,4 +29,3 @@ services: - MSSQL_DB=gorm - MSSQL_USER=gorm - MSSQL_PASSWORD=LoremIpsum86 - diff --git a/go.mod b/go.mod index 4da7ed1..78baff4 100644 --- a/go.mod +++ b/go.mod @@ -3,14 +3,13 @@ module gorm.io/playground go 1.16 require ( + github.com/denisenkom/go-mssqldb v0.12.2 // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect - github.com/jackc/pgx/v4 v4.16.1 // indirect - golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 // indirect - gorm.io/driver/mysql v1.3.3 - gorm.io/driver/postgres v1.3.5 - gorm.io/driver/sqlite v1.3.2 - gorm.io/driver/sqlserver v1.3.2 - gorm.io/gorm v1.23.4 + gorm.io/driver/mysql v1.4.1 + gorm.io/driver/postgres v1.4.4 + gorm.io/driver/sqlite v1.4.2 + gorm.io/driver/sqlserver v1.4.1 + gorm.io/gorm v1.24.0 ) replace gorm.io/gorm => ./gorm diff --git a/test.sh b/test.sh index 16901b0..7df9088 100755 --- a/test.sh +++ b/test.sh @@ -9,7 +9,22 @@ fi [ -d gorm ] || (echo "git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}')"; git clone --depth 1 -b $(cat main_test.go | grep GORM_BRANCH | awk '{print $3}') $(cat main_test.go | grep GORM_REPO | awk '{print $3}')) -go get -u ./... +go get -u -t ./... + +# SqlServer for Mac M1 +if [[ -z $GITHUB_ACTION ]]; then + if [[ $(uname -a) == *" arm64" ]]; then + MSSQL_IMAGE=mcr.microsoft.com/azure-sql-edge docker-compose up --detach --quiet-pull || true + echo "starting" + go install github.com/microsoft/go-sqlcmd/cmd/sqlcmd@latest || true + SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF DB_ID('gorm') IS NULL CREATE DATABASE gorm" > /dev/null || true + SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF SUSER_ID (N'gorm') IS NULL CREATE LOGIN gorm WITH PASSWORD = 'LoremIpsum86';" > /dev/null || true + SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF USER_ID (N'gorm') IS NULL CREATE USER gorm FROM LOGIN gorm; ALTER SERVER ROLE sysadmin ADD MEMBER [gorm];" > /dev/null || true + else + docker-compose up --detach --quiet-pull + echo "starting..." + fi +fi for dialect in "${dialects[@]}" ; do if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ]