Skip to content

Commit ecf13ab

Browse files
committed
feat(tests): support pure-go sqlite driver
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
1 parent 2066138 commit ecf13ab

File tree

3 files changed

+82
-57
lines changed

3 files changed

+82
-57
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ jobs:
1616
sqlite:
1717
strategy:
1818
matrix:
19-
go: ['1.19', '1.18']
19+
go: ['^1', '1.19', '1.18']
2020
platform: [ubuntu-latest] # can not run in windows OS
21+
cgo: ['0', '1']
2122
runs-on: ${{ matrix.platform }}
2223

2324
steps:
@@ -36,7 +37,7 @@ jobs:
3637
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}
3738

3839
- name: Tests
39-
run: GITHUB_ACTION=true GORM_DIALECT=sqlite ./tests/tests_all.sh
40+
run: CGO_ENABLED=${{ matrix.cgo }} GITHUB_ACTION=true GORM_DIALECT=sqlite ./tests/tests_all.sh
4041

4142
mysql:
4243
strategy:

tests/go.mod

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,49 @@
11
module gorm.io/gorm/tests
22

3-
go 1.16
3+
go 1.18
4+
5+
replace gorm.io/driver/sqlite => github.com/aymanbagabas/sqlite v1.5.3-0.20230705230942-b2a43d7d4596
46

57
require (
68
github.com/google/uuid v1.3.0
7-
github.com/jackc/pgx/v5 v5.3.1 // indirect
89
github.com/jinzhu/now v1.1.5
9-
github.com/lib/pq v1.10.8
10-
github.com/mattn/go-sqlite3 v1.14.16 // indirect
11-
gorm.io/driver/mysql v1.5.0
12-
gorm.io/driver/postgres v1.5.0
13-
gorm.io/driver/sqlite v1.5.0
10+
github.com/lib/pq v1.10.9
11+
gorm.io/driver/mysql v1.5.1
12+
gorm.io/driver/postgres v1.5.2
13+
gorm.io/driver/sqlite v1.5.2
1414
gorm.io/driver/sqlserver v1.5.1
15-
gorm.io/gorm v1.25.1
15+
gorm.io/gorm v1.25.2-0.20230530020048-26663ab9bf55
16+
)
17+
18+
require (
19+
github.com/dustin/go-humanize v1.0.1 // indirect
20+
github.com/go-sql-driver/mysql v1.7.1 // indirect
21+
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
22+
github.com/golang-sql/sqlexp v0.1.0 // indirect
23+
github.com/jackc/pgpassfile v1.0.0 // indirect
24+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
25+
github.com/jackc/pgx/v5 v5.4.1 // indirect
26+
github.com/jinzhu/inflection v1.0.0 // indirect
27+
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
28+
github.com/mattn/go-isatty v0.0.19 // indirect
29+
github.com/mattn/go-sqlite3 v1.14.17 // indirect
30+
github.com/microsoft/go-mssqldb v1.3.0 // indirect
31+
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
32+
golang.org/x/crypto v0.11.0 // indirect
33+
golang.org/x/mod v0.12.0 // indirect
34+
golang.org/x/sys v0.10.0 // indirect
35+
golang.org/x/text v0.11.0 // indirect
36+
golang.org/x/tools v0.11.0 // indirect
37+
lukechampine.com/uint128 v1.3.0 // indirect
38+
modernc.org/cc/v3 v3.41.0 // indirect
39+
modernc.org/ccgo/v3 v3.16.14 // indirect
40+
modernc.org/libc v1.24.1 // indirect
41+
modernc.org/mathutil v1.6.0 // indirect
42+
modernc.org/memory v1.6.0 // indirect
43+
modernc.org/opt v0.1.3 // indirect
44+
modernc.org/sqlite v1.23.1 // indirect
45+
modernc.org/strutil v1.1.3 // indirect
46+
modernc.org/token v1.1.0 // indirect
1647
)
1748

1849
replace gorm.io/gorm => ../

tests/tests_all.sh

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,54 @@
11
#!/bin/bash -e
22

3-
dialects=("sqlite" "mysql" "postgres" "sqlserver" "tidb")
3+
dialects=("sqlite")
44

55
if [[ $(pwd) == *"gorm/tests"* ]]; then
6-
cd ..
6+
cd ..
77
fi
88

9-
if [ -d tests ]
10-
then
11-
cd tests
12-
go get -u -t ./...
13-
go mod download
14-
go mod tidy
15-
cd ..
9+
if [ -d tests ]; then
10+
cd tests
11+
go get -u -t ./...
12+
go mod download
13+
go mod tidy
14+
cd ..
1615
fi
1716

1817
# SqlServer for Mac M1
1918
if [[ -z $GITHUB_ACTION ]]; then
20-
if [ -d tests ]
21-
then
22-
cd tests
23-
if [[ $(uname -a) == *" arm64" ]]; then
24-
MSSQL_IMAGE=mcr.microsoft.com/azure-sql-edge docker-compose start || true
25-
go install github.com/microsoft/go-sqlcmd/cmd/sqlcmd@latest || true
26-
SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF DB_ID('gorm') IS NULL CREATE DATABASE gorm" > /dev/null || true
27-
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
28-
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
29-
else
30-
docker-compose start
31-
fi
32-
cd ..
33-
fi
19+
if [ -d tests ]; then
20+
cd tests
21+
if [[ $(uname -a) == *" arm64" ]]; then
22+
MSSQL_IMAGE=mcr.microsoft.com/azure-sql-edge docker-compose start || true
23+
go install github.com/microsoft/go-sqlcmd/cmd/sqlcmd@latest || true
24+
SQLCMDPASSWORD=LoremIpsum86 sqlcmd -U sa -S localhost:9930 -Q "IF DB_ID('gorm') IS NULL CREATE DATABASE gorm" >/dev/null || true
25+
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
26+
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
27+
else
28+
docker-compose start
29+
fi
30+
cd ..
31+
fi
3432
fi
3533

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

37-
for dialect in "${dialects[@]}" ; do
38-
if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ]
39-
then
40-
echo "testing ${dialect}..."
41-
42-
if [ "$GORM_VERBOSE" = "" ]
43-
then
44-
GORM_DIALECT=${dialect} go test -race -count=1 ./...
45-
if [ -d tests ]
46-
then
47-
cd tests
48-
GORM_DIALECT=${dialect} go test -race -count=1 ./...
49-
cd ..
50-
fi
51-
else
52-
GORM_DIALECT=${dialect} go test -race -count=1 -v ./...
53-
if [ -d tests ]
54-
then
55-
cd tests
56-
GORM_DIALECT=${dialect} go test -race -count=1 -v ./...
57-
cd ..
58-
fi
59-
fi
60-
fi
38+
if [ "$GORM_VERBOSE" = "" ]; then
39+
GORM_DIALECT=${dialect} go test -race -count=1 ./...
40+
if [ -d tests ]; then
41+
cd tests
42+
GORM_DIALECT=${dialect} go test -race -count=1 ./...
43+
cd ..
44+
fi
45+
else
46+
GORM_DIALECT=${dialect} go test -race -count=1 -v ./...
47+
if [ -d tests ]; then
48+
cd tests
49+
GORM_DIALECT=${dialect} go test -race -count=1 -v ./...
50+
cd ..
51+
fi
52+
fi
53+
fi
6154
done

0 commit comments

Comments
 (0)