1414
1515//go:build e2e
1616
17- package creator
17+ package creator_test
1818
1919import (
2020 "context"
2121 "errors"
2222 "testing"
2323 "time"
2424
25+ xcreator "github.com/chenmingyong0423/go-mongox/v2/creator"
2526 "github.com/chenmingyong0423/go-mongox/v2/field"
2627
2728 "github.com/chenmingyong0423/go-mongox/v2/callback"
@@ -70,7 +71,7 @@ func newCollection(t *testing.T) *mongo.Collection {
7071
7172func TestCreator_e2e_One (t * testing.T ) {
7273 collection := newCollection (t )
73- creator := NewCreator [User ](collection , callback .InitializeCallbacks (), field .ParseFields (User {}))
74+ creator := xcreator . NewCreator [User ](collection , callback .InitializeCallbacks (), field .ParseFields (User {}))
7475
7576 type globalHook struct {
7677 opType operation.OpType
@@ -86,8 +87,8 @@ func TestCreator_e2e_One(t *testing.T) {
8687 ctx context.Context
8788 doc * User
8889 globalHook []globalHook
89- beforeHook []hookFn [User ]
90- afterHook []hookFn [User ]
90+ beforeHook []xcreator. HookFn [User ]
91+ afterHook []xcreator. HookFn [User ]
9192
9293 wantError assert.ErrorAssertionFunc
9394 }{
@@ -226,8 +227,8 @@ func TestCreator_e2e_One(t *testing.T) {
226227 options .InsertOne ().SetComment ("test" ),
227228 },
228229 doc : nil ,
229- beforeHook : []hookFn [User ]{
230- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
230+ beforeHook : []xcreator. HookFn [User ]{
231+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
231232 return errors .New ("before hook error" )
232233 },
233234 },
@@ -251,8 +252,8 @@ func TestCreator_e2e_One(t *testing.T) {
251252 Name : "Mingyong Chen" ,
252253 Age : 18 ,
253254 },
254- afterHook : []hookFn [User ]{
255- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
255+ afterHook : []xcreator. HookFn [User ]{
256+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
256257 return errors .New ("after hook error" )
257258 },
258259 },
@@ -276,16 +277,16 @@ func TestCreator_e2e_One(t *testing.T) {
276277 Name : "Mingyong Chen" ,
277278 Age : 18 ,
278279 },
279- beforeHook : []hookFn [User ]{
280- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
280+ beforeHook : []xcreator. HookFn [User ]{
281+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
281282 if opContext .Doc == nil {
282283 return errors .New ("before hook error" )
283284 }
284285 return nil
285286 },
286287 },
287- afterHook : []hookFn [User ]{
288- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
288+ afterHook : []xcreator. HookFn [User ]{
289+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
289290 if opContext == nil {
290291 return errors .New ("after hook error" )
291292 }
@@ -322,8 +323,8 @@ func TestCreator_e2e_One(t *testing.T) {
322323 Name : "Mingyong Chen" ,
323324 Age : 18 ,
324325 },
325- afterHook : []hookFn [User ]{
326- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
326+ afterHook : []xcreator. HookFn [User ]{
327+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
327328 user := opContext .Doc
328329 if user == nil {
329330 return errors .New ("user is nil" )
@@ -372,7 +373,7 @@ func TestCreator_e2e_One(t *testing.T) {
372373 t .Run (tc .name , func (t * testing.T ) {
373374 tc .before (tc .ctx , t )
374375 for _ , hook := range tc .globalHook {
375- creator .dbCallbacks .Register (hook .opType , hook .name , hook .fn )
376+ creator .DBCallbacks .Register (hook .opType , hook .name , hook .fn )
376377 }
377378 insertOneResult , err := creator .RegisterBeforeHooks (tc .beforeHook ... ).
378379 RegisterAfterHooks (tc .afterHook ... ).InsertOne (tc .ctx , tc .doc , tc .opts ... )
@@ -384,17 +385,17 @@ func TestCreator_e2e_One(t *testing.T) {
384385 require .NotNil (t , insertOneResult .InsertedID )
385386 }
386387 for _ , hook := range tc .globalHook {
387- creator .dbCallbacks .Remove (hook .opType , hook .name )
388+ creator .DBCallbacks .Remove (hook .opType , hook .name )
388389 }
389- creator .beforeHooks = nil
390- creator .afterHooks = nil
390+ creator .BeforeHooks = nil
391+ creator .AfterHooks = nil
391392 })
392393 }
393394}
394395
395396func TestCreator_e2e_Many (t * testing.T ) {
396397 collection := newCollection (t )
397- creator := NewCreator [User ](collection , callback .InitializeCallbacks (), field .ParseFields (User {}))
398+ creator := xcreator . NewCreator [User ](collection , callback .InitializeCallbacks (), field .ParseFields (User {}))
398399
399400 type globalHook struct {
400401 opType operation.OpType
@@ -411,8 +412,8 @@ func TestCreator_e2e_Many(t *testing.T) {
411412 docs []* User
412413 opts []options.Lister [options.InsertManyOptions ]
413414 globalHook []globalHook
414- beforeHook []hookFn [User ]
415- afterHook []hookFn [User ]
415+ beforeHook []xcreator. HookFn [User ]
416+ afterHook []xcreator. HookFn [User ]
416417
417418 wantIdsLength int
418419 wantError assert.ErrorAssertionFunc
@@ -566,8 +567,8 @@ func TestCreator_e2e_Many(t *testing.T) {
566567 options .InsertMany ().SetComment ("test" ),
567568 },
568569 docs : nil ,
569- beforeHook : []hookFn [User ]{
570- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
570+ beforeHook : []xcreator. HookFn [User ]{
571+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
571572 return errors .New ("before hook error" )
572573 },
573574 },
@@ -597,8 +598,8 @@ func TestCreator_e2e_Many(t *testing.T) {
597598 Age : 19 ,
598599 },
599600 },
600- afterHook : []hookFn [User ]{
601- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
601+ afterHook : []xcreator. HookFn [User ]{
602+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
602603 return errors .New ("after hook error" )
603604 },
604605 },
@@ -628,16 +629,16 @@ func TestCreator_e2e_Many(t *testing.T) {
628629 Age : 19 ,
629630 },
630631 },
631- beforeHook : []hookFn [User ]{
632- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
632+ beforeHook : []xcreator. HookFn [User ]{
633+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
633634 if len (opContext .Docs ) != 2 {
634635 return errors .New ("before hook error" )
635636 }
636637 return nil
637638 },
638639 },
639- afterHook : []hookFn [User ]{
640- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
640+ afterHook : []xcreator. HookFn [User ]{
641+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
641642 if opContext == nil {
642643 return errors .New ("after hook error" )
643644 }
@@ -683,8 +684,8 @@ func TestCreator_e2e_Many(t *testing.T) {
683684 Age : 18 ,
684685 },
685686 },
686- afterHook : []hookFn [User ]{
687- func (ctx context.Context , opContext * OpContext [User ], opts ... any ) error {
687+ afterHook : []xcreator. HookFn [User ]{
688+ func (ctx context.Context , opContext * xcreator. OpContext [User ], opts ... any ) error {
688689 users := opContext .Docs
689690 if users == nil {
690691 return errors .New ("users is nil" )
@@ -736,7 +737,7 @@ func TestCreator_e2e_Many(t *testing.T) {
736737 t .Run (tc .name , func (t * testing.T ) {
737738 tc .before (tc .ctx , t )
738739 for _ , hook := range tc .globalHook {
739- creator .dbCallbacks .Register (hook .opType , hook .name , hook .fn )
740+ creator .DBCallbacks .Register (hook .opType , hook .name , hook .fn )
740741 }
741742 insertManyResult , err := creator .RegisterBeforeHooks (tc .beforeHook ... ).
742743 RegisterAfterHooks (tc .afterHook ... ).InsertMany (tc .ctx , tc .docs , tc .opts ... )
@@ -749,10 +750,10 @@ func TestCreator_e2e_Many(t *testing.T) {
749750 require .Len (t , insertManyResult .InsertedIDs , tc .wantIdsLength )
750751 }
751752 for _ , hook := range tc .globalHook {
752- creator .dbCallbacks .Remove (hook .opType , hook .name )
753+ creator .DBCallbacks .Remove (hook .opType , hook .name )
753754 }
754- creator .beforeHooks = nil
755- creator .afterHooks = nil
755+ creator .BeforeHooks = nil
756+ creator .AfterHooks = nil
756757 })
757758 }
758759}
0 commit comments