From 57990f605ddb853ae606bb4171c3934434ea4afc Mon Sep 17 00:00:00 2001 From: tohru <65994850+Tohrusky@users.noreply.github.com> Date: Thu, 24 Aug 2023 18:28:41 +0800 Subject: [PATCH 01/31] delete dal test --- dal/query/comment.gen_test.go | 145 --------------------------------- dal/query/favorite.gen_test.go | 145 --------------------------------- dal/query/follow.gen_test.go | 145 --------------------------------- dal/query/gen_test.db | Bin 110592 -> 0 bytes dal/query/gen_test.go | 123 ---------------------------- dal/query/message.gen_test.go | 145 --------------------------------- dal/query/user.gen_test.go | 145 --------------------------------- dal/query/video.gen_test.go | 145 --------------------------------- module/gen/gen.go | 2 +- 9 files changed, 1 insertion(+), 994 deletions(-) delete mode 100644 dal/query/comment.gen_test.go delete mode 100644 dal/query/favorite.gen_test.go delete mode 100644 dal/query/follow.gen_test.go delete mode 100644 dal/query/gen_test.db delete mode 100644 dal/query/gen_test.go delete mode 100644 dal/query/message.gen_test.go delete mode 100644 dal/query/user.gen_test.go delete mode 100644 dal/query/video.gen_test.go diff --git a/dal/query/comment.gen_test.go b/dal/query/comment.gen_test.go deleted file mode 100644 index d6d6857..0000000 --- a/dal/query/comment.gen_test.go +++ /dev/null @@ -1,145 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package query - -import ( - "context" - "fmt" - "testing" - - "github.com/Biu-X/TikTok/dal/model" - "gorm.io/gen" - "gorm.io/gen/field" - "gorm.io/gorm/clause" -) - -func init() { - InitializeDB() - err := db.AutoMigrate(&model.Comment{}) - if err != nil { - fmt.Printf("Error: AutoMigrate(&model.Comment{}) fail: %s", err) - } -} - -func Test_commentQuery(t *testing.T) { - comment := newComment(db) - comment = *comment.As(comment.TableName()) - _do := comment.WithContext(context.Background()).Debug() - - primaryKey := field.NewString(comment.TableName(), clause.PrimaryKey) - _, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete() - if err != nil { - t.Error("clean table fail:", err) - return - } - - _, ok := comment.GetFieldByName("") - if ok { - t.Error("GetFieldByName(\"\") from comment success") - } - - err = _do.Create(&model.Comment{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.Save(&model.Comment{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.CreateInBatches([]*model.Comment{{}, {}}, 10) - if err != nil { - t.Error("create item in table fail:", err) - } - - _, err = _do.Select(comment.ALL).Take() - if err != nil { - t.Error("Take() on table fail:", err) - } - - _, err = _do.First() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Last() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatch() on table fail:", err) - } - - err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.Comment{}, 10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatches() on table fail:", err) - } - - _, err = _do.Select(comment.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() - if err != nil { - t.Error("Find() on table fail:", err) - } - - _, err = _do.Distinct(primaryKey).Take() - if err != nil { - t.Error("select Distinct() on table fail:", err) - } - - _, err = _do.Select(comment.ALL).Omit(primaryKey).Take() - if err != nil { - t.Error("Omit() on table fail:", err) - } - - _, err = _do.Group(primaryKey).Find() - if err != nil { - t.Error("Group() on table fail:", err) - } - - _, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find() - if err != nil { - t.Error("Scopes() on table fail:", err) - } - - _, _, err = _do.FindByPage(0, 1) - if err != nil { - t.Error("FindByPage() on table fail:", err) - } - - _, err = _do.ScanByPage(&model.Comment{}, 0, 1) - if err != nil { - t.Error("ScanByPage() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() - if err != nil { - t.Error("FirstOrInit() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() - if err != nil { - t.Error("FirstOrCreate() on table fail:", err) - } - - var _a _another - var _aPK = field.NewString(_a.TableName(), clause.PrimaryKey) - - err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("Join() on table fail:", err) - } - - err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("LeftJoin() on table fail:", err) - } - - _, err = _do.Not().Or().Clauses().Take() - if err != nil { - t.Error("Not/Or/Clauses on table fail:", err) - } -} diff --git a/dal/query/favorite.gen_test.go b/dal/query/favorite.gen_test.go deleted file mode 100644 index 7eb7302..0000000 --- a/dal/query/favorite.gen_test.go +++ /dev/null @@ -1,145 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package query - -import ( - "context" - "fmt" - "testing" - - "github.com/Biu-X/TikTok/dal/model" - "gorm.io/gen" - "gorm.io/gen/field" - "gorm.io/gorm/clause" -) - -func init() { - InitializeDB() - err := db.AutoMigrate(&model.Favorite{}) - if err != nil { - fmt.Printf("Error: AutoMigrate(&model.Favorite{}) fail: %s", err) - } -} - -func Test_favoriteQuery(t *testing.T) { - favorite := newFavorite(db) - favorite = *favorite.As(favorite.TableName()) - _do := favorite.WithContext(context.Background()).Debug() - - primaryKey := field.NewString(favorite.TableName(), clause.PrimaryKey) - _, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete() - if err != nil { - t.Error("clean table fail:", err) - return - } - - _, ok := favorite.GetFieldByName("") - if ok { - t.Error("GetFieldByName(\"\") from favorite success") - } - - err = _do.Create(&model.Favorite{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.Save(&model.Favorite{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.CreateInBatches([]*model.Favorite{{}, {}}, 10) - if err != nil { - t.Error("create item in table fail:", err) - } - - _, err = _do.Select(favorite.ALL).Take() - if err != nil { - t.Error("Take() on table fail:", err) - } - - _, err = _do.First() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Last() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatch() on table fail:", err) - } - - err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.Favorite{}, 10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatches() on table fail:", err) - } - - _, err = _do.Select(favorite.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() - if err != nil { - t.Error("Find() on table fail:", err) - } - - _, err = _do.Distinct(primaryKey).Take() - if err != nil { - t.Error("select Distinct() on table fail:", err) - } - - _, err = _do.Select(favorite.ALL).Omit(primaryKey).Take() - if err != nil { - t.Error("Omit() on table fail:", err) - } - - _, err = _do.Group(primaryKey).Find() - if err != nil { - t.Error("Group() on table fail:", err) - } - - _, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find() - if err != nil { - t.Error("Scopes() on table fail:", err) - } - - _, _, err = _do.FindByPage(0, 1) - if err != nil { - t.Error("FindByPage() on table fail:", err) - } - - _, err = _do.ScanByPage(&model.Favorite{}, 0, 1) - if err != nil { - t.Error("ScanByPage() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() - if err != nil { - t.Error("FirstOrInit() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() - if err != nil { - t.Error("FirstOrCreate() on table fail:", err) - } - - var _a _another - var _aPK = field.NewString(_a.TableName(), clause.PrimaryKey) - - err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("Join() on table fail:", err) - } - - err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("LeftJoin() on table fail:", err) - } - - _, err = _do.Not().Or().Clauses().Take() - if err != nil { - t.Error("Not/Or/Clauses on table fail:", err) - } -} diff --git a/dal/query/follow.gen_test.go b/dal/query/follow.gen_test.go deleted file mode 100644 index 52ef271..0000000 --- a/dal/query/follow.gen_test.go +++ /dev/null @@ -1,145 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package query - -import ( - "context" - "fmt" - "testing" - - "github.com/Biu-X/TikTok/dal/model" - "gorm.io/gen" - "gorm.io/gen/field" - "gorm.io/gorm/clause" -) - -func init() { - InitializeDB() - err := db.AutoMigrate(&model.Follow{}) - if err != nil { - fmt.Printf("Error: AutoMigrate(&model.Follow{}) fail: %s", err) - } -} - -func Test_followQuery(t *testing.T) { - follow := newFollow(db) - follow = *follow.As(follow.TableName()) - _do := follow.WithContext(context.Background()).Debug() - - primaryKey := field.NewString(follow.TableName(), clause.PrimaryKey) - _, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete() - if err != nil { - t.Error("clean table fail:", err) - return - } - - _, ok := follow.GetFieldByName("") - if ok { - t.Error("GetFieldByName(\"\") from follow success") - } - - err = _do.Create(&model.Follow{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.Save(&model.Follow{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.CreateInBatches([]*model.Follow{{}, {}}, 10) - if err != nil { - t.Error("create item in table fail:", err) - } - - _, err = _do.Select(follow.ALL).Take() - if err != nil { - t.Error("Take() on table fail:", err) - } - - _, err = _do.First() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Last() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatch() on table fail:", err) - } - - err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.Follow{}, 10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatches() on table fail:", err) - } - - _, err = _do.Select(follow.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() - if err != nil { - t.Error("Find() on table fail:", err) - } - - _, err = _do.Distinct(primaryKey).Take() - if err != nil { - t.Error("select Distinct() on table fail:", err) - } - - _, err = _do.Select(follow.ALL).Omit(primaryKey).Take() - if err != nil { - t.Error("Omit() on table fail:", err) - } - - _, err = _do.Group(primaryKey).Find() - if err != nil { - t.Error("Group() on table fail:", err) - } - - _, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find() - if err != nil { - t.Error("Scopes() on table fail:", err) - } - - _, _, err = _do.FindByPage(0, 1) - if err != nil { - t.Error("FindByPage() on table fail:", err) - } - - _, err = _do.ScanByPage(&model.Follow{}, 0, 1) - if err != nil { - t.Error("ScanByPage() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() - if err != nil { - t.Error("FirstOrInit() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() - if err != nil { - t.Error("FirstOrCreate() on table fail:", err) - } - - var _a _another - var _aPK = field.NewString(_a.TableName(), clause.PrimaryKey) - - err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("Join() on table fail:", err) - } - - err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("LeftJoin() on table fail:", err) - } - - _, err = _do.Not().Or().Clauses().Take() - if err != nil { - t.Error("Not/Or/Clauses on table fail:", err) - } -} diff --git a/dal/query/gen_test.db b/dal/query/gen_test.db deleted file mode 100644 index b984d9b45dbce6332d273fe71644660eb1960d5d..0000000000000000000000000000000000000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ZznC|1Y!i|1vxO@BRNjkvtUWA8rtU00bZa0SG_<0uX=z1Rwwb2n?2hBuYYp-Pra2 zB6&o=|36q2L~S4d0SG_<0uX=z1Rwwb2tWV=5by;2>;EzS#~uLz2tWV=5P$##AOHaf zKmY;|7+irsAQ55b|AlSBhTs1i+*+e%5P$##AOHafKmY;|fB*y_0D%D#U|0C}as5C3 z|K9+$IjRBy2tWV=5P$##AOHafKmY=REr8$uAMEx;?H~XF2tWV=5P$##AOHafKmYz$ce;U!q5zJQp-*n>7;JuGiKhjri}EoWf^<5Y+lnQV*Lh2dj@8*md@F#fN9F2jfQn;8H97lD fail:", err) - return - } - - _, ok := message.GetFieldByName("") - if ok { - t.Error("GetFieldByName(\"\") from message success") - } - - err = _do.Create(&model.Message{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.Save(&model.Message{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.CreateInBatches([]*model.Message{{}, {}}, 10) - if err != nil { - t.Error("create item in table fail:", err) - } - - _, err = _do.Select(message.ALL).Take() - if err != nil { - t.Error("Take() on table fail:", err) - } - - _, err = _do.First() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Last() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatch() on table fail:", err) - } - - err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.Message{}, 10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatches() on table fail:", err) - } - - _, err = _do.Select(message.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() - if err != nil { - t.Error("Find() on table fail:", err) - } - - _, err = _do.Distinct(primaryKey).Take() - if err != nil { - t.Error("select Distinct() on table fail:", err) - } - - _, err = _do.Select(message.ALL).Omit(primaryKey).Take() - if err != nil { - t.Error("Omit() on table fail:", err) - } - - _, err = _do.Group(primaryKey).Find() - if err != nil { - t.Error("Group() on table fail:", err) - } - - _, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find() - if err != nil { - t.Error("Scopes() on table fail:", err) - } - - _, _, err = _do.FindByPage(0, 1) - if err != nil { - t.Error("FindByPage() on table fail:", err) - } - - _, err = _do.ScanByPage(&model.Message{}, 0, 1) - if err != nil { - t.Error("ScanByPage() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() - if err != nil { - t.Error("FirstOrInit() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() - if err != nil { - t.Error("FirstOrCreate() on table fail:", err) - } - - var _a _another - var _aPK = field.NewString(_a.TableName(), clause.PrimaryKey) - - err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("Join() on table fail:", err) - } - - err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("LeftJoin() on table fail:", err) - } - - _, err = _do.Not().Or().Clauses().Take() - if err != nil { - t.Error("Not/Or/Clauses on table fail:", err) - } -} diff --git a/dal/query/user.gen_test.go b/dal/query/user.gen_test.go deleted file mode 100644 index f46b2c0..0000000 --- a/dal/query/user.gen_test.go +++ /dev/null @@ -1,145 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package query - -import ( - "context" - "fmt" - "testing" - - "github.com/Biu-X/TikTok/dal/model" - "gorm.io/gen" - "gorm.io/gen/field" - "gorm.io/gorm/clause" -) - -func init() { - InitializeDB() - err := db.AutoMigrate(&model.User{}) - if err != nil { - fmt.Printf("Error: AutoMigrate(&model.User{}) fail: %s", err) - } -} - -func Test_userQuery(t *testing.T) { - user := newUser(db) - user = *user.As(user.TableName()) - _do := user.WithContext(context.Background()).Debug() - - primaryKey := field.NewString(user.TableName(), clause.PrimaryKey) - _, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete() - if err != nil { - t.Error("clean table fail:", err) - return - } - - _, ok := user.GetFieldByName("") - if ok { - t.Error("GetFieldByName(\"\") from user success") - } - - err = _do.Create(&model.User{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.Save(&model.User{}) - if err != nil { - t.Error("create item in table fail:", err) - } - - err = _do.CreateInBatches([]*model.User{{}, {}}, 10) - if err != nil { - t.Error("create item in table fail:", err) - } - - _, err = _do.Select(user.ALL).Take() - if err != nil { - t.Error("Take() on table fail:", err) - } - - _, err = _do.First() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Last() - if err != nil { - t.Error("First() on table fail:", err) - } - - _, err = _do.Where(primaryKey.IsNotNull()).FindInBatch(10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatch() on table fail:", err) - } - - err = _do.Where(primaryKey.IsNotNull()).FindInBatches(&[]*model.User{}, 10, func(tx gen.Dao, batch int) error { return nil }) - if err != nil { - t.Error("FindInBatches() on table fail:", err) - } - - _, err = _do.Select(user.ALL).Where(primaryKey.IsNotNull()).Order(primaryKey.Desc()).Find() - if err != nil { - t.Error("Find() on table fail:", err) - } - - _, err = _do.Distinct(primaryKey).Take() - if err != nil { - t.Error("select Distinct() on table fail:", err) - } - - _, err = _do.Select(user.ALL).Omit(primaryKey).Take() - if err != nil { - t.Error("Omit() on table fail:", err) - } - - _, err = _do.Group(primaryKey).Find() - if err != nil { - t.Error("Group() on table fail:", err) - } - - _, err = _do.Scopes(func(dao gen.Dao) gen.Dao { return dao.Where(primaryKey.IsNotNull()) }).Find() - if err != nil { - t.Error("Scopes() on table fail:", err) - } - - _, _, err = _do.FindByPage(0, 1) - if err != nil { - t.Error("FindByPage() on table fail:", err) - } - - _, err = _do.ScanByPage(&model.User{}, 0, 1) - if err != nil { - t.Error("ScanByPage() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrInit() - if err != nil { - t.Error("FirstOrInit() on table fail:", err) - } - - _, err = _do.Attrs(primaryKey).Assign(primaryKey).FirstOrCreate() - if err != nil { - t.Error("FirstOrCreate() on table fail:", err) - } - - var _a _another - var _aPK = field.NewString(_a.TableName(), clause.PrimaryKey) - - err = _do.Join(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("Join() on table fail:", err) - } - - err = _do.LeftJoin(&_a, primaryKey.EqCol(_aPK)).Scan(map[string]interface{}{}) - if err != nil { - t.Error("LeftJoin() on table fail:", err) - } - - _, err = _do.Not().Or().Clauses().Take() - if err != nil { - t.Error("Not/Or/Clauses on table fail:", err) - } -} diff --git a/dal/query/video.gen_test.go b/dal/query/video.gen_test.go deleted file mode 100644 index af30a07..0000000 --- a/dal/query/video.gen_test.go +++ /dev/null @@ -1,145 +0,0 @@ -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. -// Code generated by gorm.io/gen. DO NOT EDIT. - -package query - -import ( - "context" - "fmt" - "testing" - - "github.com/Biu-X/TikTok/dal/model" - "gorm.io/gen" - "gorm.io/gen/field" - "gorm.io/gorm/clause" -) - -func init() { - InitializeDB() - err := db.AutoMigrate(&model.Video{}) - if err != nil { - fmt.Printf("Error: AutoMigrate(&model.Video{}) fail: %s", err) - } -} - -func Test_videoQuery(t *testing.T) { - video := newVideo(db) - video = *video.As(video.TableName()) - _do := video.WithContext(context.Background()).Debug() - - primaryKey := field.NewString(video.TableName(), clause.PrimaryKey) - _, err := _do.Unscoped().Where(primaryKey.IsNotNull()).Delete() - if err != nil { - t.Error("clean table