Skip to content

Commit

Permalink
feat(tests): support pure-go sqlite driver
Browse files Browse the repository at this point in the history
This tests the sqlite with/out CGO, updates the minimum tests go version
to 1.18, and adds the latest go version `^1` to the sqlite CI tests.

Related: go-gorm/sqlite#161
  • Loading branch information
aymanbagabas committed Jul 6, 2023
1 parent 2066138 commit d09cb70
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 55 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Expand Up @@ -16,7 +16,7 @@ jobs:
sqlite:
strategy:
matrix:
go: ['1.19', '1.18']
go: ['^1', '1.19', '1.18']
platform: [ubuntu-latest] # can not run in windows OS
runs-on: ${{ matrix.platform }}

Expand Down
47 changes: 39 additions & 8 deletions tests/go.mod
@@ -1,18 +1,49 @@
module gorm.io/gorm/tests

go 1.16
go 1.18

replace gorm.io/driver/sqlite => github.com/aymanbagabas/sqlite v1.5.3-0.20230705235344-744e464ebb48

require (
github.com/google/uuid v1.3.0
github.com/jackc/pgx/v5 v5.3.1 // indirect
github.com/jinzhu/now v1.1.5
github.com/lib/pq v1.10.8
github.com/mattn/go-sqlite3 v1.14.16 // indirect
gorm.io/driver/mysql v1.5.0
gorm.io/driver/postgres v1.5.0
gorm.io/driver/sqlite v1.5.0
github.com/lib/pq v1.10.9
gorm.io/driver/mysql v1.5.1
gorm.io/driver/postgres v1.5.2
gorm.io/driver/sqlite v1.5.2
gorm.io/driver/sqlserver v1.5.1
gorm.io/gorm v1.25.1
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55
)

require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/microsoft/go-mssqldb v1.3.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.11.0 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.14 // indirect
modernc.org/libc v1.24.1 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.6.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.23.1 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.1.0 // indirect
)

replace gorm.io/gorm => ../
104 changes: 58 additions & 46 deletions tests/tests_all.sh
Expand Up @@ -3,59 +3,71 @@
dialects=("sqlite" "mysql" "postgres" "sqlserver" "tidb")

if [[ $(pwd) == *"gorm/tests"* ]]; then
cd ..
cd ..
fi

if [ -d tests ]
then
cd tests
go get -u -t ./...
go mod download
go mod tidy
cd ..
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('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 start
fi
cd ..
fi
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('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 start
fi
cd ..
fi
fi

for dialect in "${dialects[@]}"; do
if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ]; then
echo "testing ${dialect}..."

for dialect in "${dialects[@]}" ; do
if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ]
then
echo "testing ${dialect}..."

if [ "$GORM_VERBOSE" = "" ]
then
GORM_DIALECT=${dialect} go test -race -count=1 ./...
if [ -d tests ]
then
cd tests
GORM_DIALECT=${dialect} go test -race -count=1 ./...
cd ..
fi
else
GORM_DIALECT=${dialect} go test -race -count=1 -v ./...
if [ -d tests ]
then
cd tests
GORM_DIALECT=${dialect} go test -race -count=1 -v ./...
cd ..
fi
fi
fi
cmd="GORM_DIALECT=${dialect} go test"
tags=("")

if [ "$GORM_DIALECT" = "sqlite" ]; then
# Test SQLite pure-go driver
tags+=("pure")
fi

for tag in "${tags[@]}"; do
echo "testing ${dialect} with tag '${tag}'"

if [ -n "$tag" ]; then
cmd="$cmd -tags ${tag}"
fi

cmd="$cmd -race -count=1 ./..."


if [ "$GORM_VERBOSE" = "" ]; then
eval $cmd
if [ -d tests ]; then
cd tests
eval $cmd
cd ..
fi
else
eval $cmd
if [ -d tests ]; then
cd tests
eval $cmd
cd ..
fi
fi
done
fi
done

0 comments on commit d09cb70

Please sign in to comment.