Skip to content

test Omit #798

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 15 additions & 15 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
module gorm.io/playground

go 1.22.0
go 1.23.0

toolchain go1.23.3
toolchain go1.24.1

require (
gorm.io/driver/mysql v1.5.7
gorm.io/driver/postgres v1.5.10
gorm.io/driver/sqlite v1.5.6
gorm.io/driver/postgres v1.5.11
gorm.io/driver/sqlite v1.5.7
gorm.io/driver/sqlserver v1.5.4
gorm.io/gen v0.3.26
gorm.io/gorm v1.25.12
)

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/go-sql-driver/mysql v1.9.2 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.1 // indirect
github.com/jackc/pgx/v5 v5.7.4 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/mattn/go-sqlite3 v1.14.24 // indirect
github.com/microsoft/go-mssqldb v1.7.2 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.27.0 // indirect
gorm.io/datatypes v1.2.4 // indirect
github.com/mattn/go-sqlite3 v1.14.27 // indirect
github.com/microsoft/go-mssqldb v1.8.0 // indirect
golang.org/x/crypto v0.37.0 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/sync v0.13.0 // indirect
golang.org/x/sys v0.32.0 // indirect
golang.org/x/text v0.24.0 // indirect
golang.org/x/tools v0.32.0 // indirect
gorm.io/datatypes v1.2.5 // indirect
gorm.io/hints v1.1.2 // indirect
gorm.io/plugin/dbresolver v1.5.3 // indirect
)
Expand Down
58 changes: 55 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,72 @@
package main

import (
"gorm.io/gorm"
"testing"
"time"
)

// GORM_REPO: https://github.com/go-gorm/gorm.git
// GORM_BRANCH: master
// TEST_DRIVERS: sqlite, mysql, postgres, sqlserver

func TestGORM(t *testing.T) {
user := User{Name: "jinzhu"}
preTime := time.Date(2025, 4, 10, 0, 0, 0, 0, time.UTC)
var preId uint = 10
user := User{
Model: gorm.Model{
ID: preId,
CreatedAt: preTime,
},
Name: "jinzhu",
}

DB.Create(&user)

var result User
if err := DB.First(&result, user.ID).Error; err != nil {
user2 := User{
Model: gorm.Model{
ID: 12,
CreatedAt: time.Date(2025, 4, 11, 0, 0, 0, 0, time.UTC),
},
Name: "jinzhu",
}

err := DB.Debug().Select("*").Omit("id").Omit("created_at").Omit("name").
Where("name = ?", "jinzhu").
Updates(user2).Error
if err != nil {
t.Errorf("Failed, got error: %v", err)
}
getUser := User{}
err = DB.First(&getUser, user2.ID).Error
if err != nil {
t.Errorf("Failed, got error: %v", err)
}
if getUser.ID != preId {
t.Errorf("id changed!!!")
}
if getUser.CreatedAt != preTime {
t.Errorf("created_at changed!!!")
}
/*
2025/04/10 23:00:53 testing sqlite3...
=== RUN TestGORM

2025/04/10 23:00:53 /Users/cruvie/cruvie-space/code-hub/open-source/playground/main_test.go:24
[1.637ms] [rows:1] INSERT INTO `users` (`created_at`,`updated_at`,`deleted_at`,`name`,`age`,`birthday`,`company_id`,`manager_id`,`active`,`id`) VALUES ("2025-04-10 00:00:00","2025-04-10 23:00:53.669",NULL,"jinzhu",0,NULL,NULL,NULL,false,10) RETURNING `id`

2025/04/10 23:00:53 /Users/cruvie/cruvie-space/code-hub/open-source/playground/main_test.go:36
[0.154ms] [rows:0] UPDATE `users` SET `id`=12,`created_at`="2025-04-11 00:00:00",`updated_at`="2025-04-10 23:00:53.671",`deleted_at`=NULL,`age`=0,`birthday`=NULL,`company_id`=NULL,`manager_id`=NULL,`active`=false WHERE name = "jinzhu" AND `users`.`deleted_at` IS NULL AND `id` = 12

2025/04/10 23:00:53 /Users/cruvie/cruvie-space/code-hub/open-source/playground/main_test.go:41 record not found
[0.043ms] [rows:0] SELECT * FROM `users` WHERE `users`.`id` = 12 AND `users`.`deleted_at` IS NULL ORDER BY `users`.`id` LIMIT 1
main_test.go:43: Failed, got error: record not found
main_test.go:46: id changed!!!
main_test.go:49: created_at changed!!!
--- FAIL: TestGORM (0.00s)

FAIL

进程 已完成,退出代码为 1
*/
}
Loading