Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SQL Server dialect name to match switch case, update failing SQL Server tests #270

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,15 @@ jobs:

services:
mssql:
image: mcmoe/mssqldocker:latest
image: mcr.microsoft.com/mssql/server:2022-latest
env:
TZ: Asia/Shanghai
ACCEPT_EULA: Y
SA_PASSWORD: LoremIpsum86
MSSQL_DB: gorm
MSSQL_USER: gorm
MSSQL_PASSWORD: LoremIpsum86
MSSQL_SA_PASSWORD: LoremIpsum86
ports:
- 9930:1433
options: >-
--health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P LoremIpsum86 -l 30 -Q \"SELECT 1\" || exit 1"
--health-cmd="/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P ${MSSQL_SA_PASSWORD} -N -C -l 30 -Q \"SELECT 1\" || exit 1"
--health-start-period 10s
--health-interval 10s
--health-timeout 5s
Expand All @@ -163,4 +161,4 @@ jobs:
key: ${{ runner.os }}-go-${{ matrix.go }}-${{ hashFiles('tests/go.mod') }}

- name: Tests
run: GORM_DIALECT=sqlserver GORM_DSN="sqlserver://gorm:LoremIpsum86@localhost:9930?database=gorm" ./test_all.sh
run: GORM_DIALECT=sqlserver GORM_DSN="sqlserver://sa:LoremIpsum86@localhost:9930?database=master" ./test_all.sh
5 changes: 5 additions & 0 deletions binuuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func NewBinUUIDv4() BinUUID {
return BinUUID(uuid.Must(uuid.NewRandom()))
}

// NewNilBinUUID generates a nil uuid.
func NewNilBinUUID() BinUUID {
return BinUUID(uuid.Nil)
}

// BinUUIDFromString returns the BinUUID representation of the specified uuidStr.
func BinUUIDFromString(uuidStr string) BinUUID {
return BinUUID(uuid.MustParse(uuidStr))
Expand Down
8 changes: 5 additions & 3 deletions binuuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestBinUUID(t *testing.T) {
AssertEqual(t, user2.UserUUID.IsNil(), false)
AssertEqual(t, user2.UserUUID.IsEmpty(), false)
tx = DB.Model(&user2).Updates(
map[string]interface{}{"user_uuid": nil},
map[string]interface{}{"user_uuid": datatypes.NewNilBinUUID()},
)
AssertEqual(t, tx.Error, nil)
AssertEqual(t, user2.UserUUID.IsNil(), true)
Expand Down Expand Up @@ -171,9 +171,11 @@ func TestBinUUIDPtr(t *testing.T) {
user1 := users[0]
AssertEqual(t, user1.UserUUID.IsNilPtr(), false)
AssertEqual(t, user1.UserUUID.IsEmptyPtr(), false)
tx := DB.Model(&user1).Updates(map[string]interface{}{"user_uuid": nil})
tx := DB.Model(&user1).Updates(map[string]interface{}{
"user_uuid": datatypes.NewNilBinUUID(),
})
AssertEqual(t, tx.Error, nil)
AssertEqual(t, user1.UserUUID.IsNilPtr(), true)
AssertEqual(t, user1.UserUUID.IsNil(), true)
AssertEqual(t, user1.UserUUID.IsEmptyPtr(), true)
}
}
2 changes: 1 addition & 1 deletion test_all.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e

dialects=("postgres" "postgres_simple" "mysql" "mssql" "sqlite")
dialects=("postgres" "postgres_simple" "mysql" "sqlserver" "sqlite")

for dialect in "${dialects[@]}" ; do
if [ "$GORM_DIALECT" = "" ] || [ "$GORM_DIALECT" = "${dialect}" ]
Expand Down
16 changes: 12 additions & 4 deletions url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func TestURL(t *testing.T) {
DB.Create(&f2)

result := StructWithURL{}
if err := DB.First(&result, "file_name = ? AND storage = ?", "FLocal1",
if err := DB.First(
&result, "file_name = ? AND storage LIKE ?",
"FLocal1",
datatypes.URL{
Scheme: "file",
Path: "/tmp/f1",
Expand All @@ -48,7 +50,9 @@ func TestURL(t *testing.T) {
AssertEqual(t, uf1.String(), result.Storage.String())

result = StructWithURL{}
if err := DB.First(&result, "file_name = ? AND storage = ?", "FRemote2",
if err := DB.First(
&result, "file_name = ? AND storage LIKE ?",
"FRemote2",
datatypes.URL{
Scheme: "sftp",
User: url.UserPassword("user", "pwd"),
Expand All @@ -66,7 +70,9 @@ func TestURL(t *testing.T) {
AssertEqual(t, us, result.Storage.String())

result = StructWithURL{}
if err := DB.First(&result, "file_name = ? AND storage = ?", "FRemote2",
if err := DB.First(
&result, "file_name = ? AND storage LIKE ?",
"FRemote2",
datatypes.URL{
Scheme: "sftp",
Opaque: "//user:[email protected]/f2",
Expand All @@ -78,7 +84,9 @@ func TestURL(t *testing.T) {
AssertEqual(t, us, result.Storage.String())

result = StructWithURL{}
if err := DB.First(&result, "file_name = ? AND storage = ?", "FRemote2",
if err := DB.First(
&result, "file_name = ? AND storage LIKE ?",
"FRemote2",
datatypes.URL{
Scheme: "sftp",
User: url.User("user"),
Expand Down
2 changes: 1 addition & 1 deletion uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (UUID) GormDBDataType(db *gorm.DB, field *schema.Field) string {
case "postgres":
return "UUID"
case "sqlserver":
return "NVARCHAR"
return "NVARCHAR(128)"
case "sqlite":
return "TEXT"
default:
Expand Down
Loading