From 8d293d44dd7e4e6f61d759cb6c9a5be2c6523c5e Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Sun, 30 Jan 2022 22:00:56 +0800 Subject: [PATCH] Fix docker-compose test env for Mac M1 --- tests/docker-compose.yml | 4 ++-- tests/go.mod | 6 +++--- tests/tests_all.sh | 17 +++++++++++++++++ tests/tests_test.go | 11 ++++++----- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/tests/docker-compose.yml b/tests/docker-compose.yml index 05e0956e..9ab4ddb6 100644 --- a/tests/docker-compose.yml +++ b/tests/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: diff --git a/tests/go.mod b/tests/go.mod index 5415cf74..f2addaa1 100644 --- a/tests/go.mod +++ b/tests/go.mod @@ -8,13 +8,13 @@ require ( github.com/jackc/pgx/v4 v4.14.1 // indirect github.com/jinzhu/now v1.1.4 github.com/lib/pq v1.10.4 - github.com/mattn/go-sqlite3 v1.14.10 // indirect - golang.org/x/crypto v0.0.0-20220126234351-aa10faf2a1f8 // indirect + github.com/mattn/go-sqlite3 v1.14.11 // indirect + golang.org/x/crypto v0.0.0-20220128200615-198e4374d7ed // indirect gorm.io/driver/mysql v1.2.3 gorm.io/driver/postgres v1.2.3 gorm.io/driver/sqlite v1.2.6 gorm.io/driver/sqlserver v1.2.1 - gorm.io/gorm v1.22.4 + gorm.io/gorm v1.22.5 ) replace gorm.io/gorm => ../ diff --git a/tests/tests_all.sh b/tests/tests_all.sh index 79e0b5b7..e1f394e5 100755 --- a/tests/tests_all.sh +++ b/tests/tests_all.sh @@ -15,6 +15,23 @@ then cd .. fi +# SqlServer for Mac M1 +if [ -d tests ] +then + cd tests + if [[ $(uname -a) == *" arm64" ]]; then + MSSQL_IMAGE=mcr.microsoft.com/azure-sql-edge docker-compose start + go install github.com/microsoft/go-sqlcmd/cmd/sqlcmd@latest + SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF DB_ID('gorm') IS NULL CREATE DATABASE gorm" > /dev/null + SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF SUSER_ID (N'gorm') IS NULL CREATE LOGIN gorm WITH PASSWORD = 'LoremIpsum86';" > /dev/null + 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 + else + docker-compose start + fi + cd .. +fi + + for dialect in "${dialects[@]}" ; do if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ] then diff --git a/tests/tests_test.go b/tests/tests_test.go index e26f358d..11b6f067 100644 --- a/tests/tests_test.go +++ b/tests/tests_test.go @@ -62,13 +62,14 @@ func OpenTestConnection() (db *gorm.DB, err error) { PreferSimpleProtocol: true, }), &gorm.Config{}) case "sqlserver": - // CREATE LOGIN gorm WITH PASSWORD = 'LoremIpsum86'; + // go install github.com/microsoft/go-sqlcmd/cmd/sqlcmd@latest + // SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 // CREATE DATABASE gorm; - // USE gorm; + // GO + // CREATE LOGIN gorm WITH PASSWORD = 'LoremIpsum86'; // CREATE USER gorm FROM LOGIN gorm; - // sp_changedbowner 'gorm'; - // npm install -g sql-cli - // mssql -u gorm -p LoremIpsum86 -d gorm -o 9930 + // ALTER SERVER ROLE sysadmin ADD MEMBER [gorm]; + // GO log.Println("testing sqlserver...") if dbDSN == "" { dbDSN = "sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm"