github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/pkg/test/patch_models/instance.go (about) 1 package patch_models 2 3 import ( 4 "reflect" 5 6 "github.com/agiledragon/gomonkey/v2" 7 8 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx" 9 "github.com/machinefi/w3bstream/pkg/depends/kit/sqlx/builder" 10 "github.com/machinefi/w3bstream/pkg/models" 11 ) 12 13 var _targetModelInstance = reflect.TypeOf(&models.Instance{}) 14 15 func InstanceList(patch *gomonkey.Patches, data []models.Instance, err error) *gomonkey.Patches { 16 return patch.ApplyMethod( 17 _targetModelInstance, 18 "List", 19 func(_ *models.Instance, _ sqlx.DBExecutor, _ builder.SqlCondition, _ ...builder.Addition) ([]models.Instance, error) { 20 return data, err 21 }, 22 ) 23 } 24 25 func InstanceFetchByInstanceID(patch *gomonkey.Patches, overwrite *models.Instance, err error) *gomonkey.Patches { 26 return patch.ApplyMethod( 27 _targetModelInstance, 28 "FetchByInstanceID", 29 func(receiver *models.Instance, _ sqlx.DBExecutor) error { 30 if overwrite != nil { 31 *receiver = *overwrite 32 } 33 return err 34 }, 35 ) 36 } 37 38 func InstanceFetchByAppletID(patch *gomonkey.Patches, overwrite *models.Instance, err error) *gomonkey.Patches { 39 return patch.ApplyMethod( 40 _targetModelInstance, 41 "FetchByAppletID", 42 func(receiver *models.Instance, _ sqlx.DBExecutor) error { 43 if overwrite != nil { 44 *receiver = *overwrite 45 } 46 return err 47 }, 48 ) 49 } 50 51 func InstanceUpdateByInstanceID(patch *gomonkey.Patches, overwrite *models.Instance, err error) *gomonkey.Patches { 52 return patch.ApplyMethod( 53 _targetModelInstance, 54 "UpdateByInstanceID", 55 func(receiver *models.Instance, _ sqlx.DBExecutor, _ ...string) error { 56 if overwrite != nil { 57 *receiver = *overwrite 58 } 59 return err 60 }, 61 ) 62 } 63 64 func InstanceCreate(patch *gomonkey.Patches, overwrite *models.Instance, err error) *gomonkey.Patches { 65 return patch.ApplyMethod( 66 _targetModelInstance, 67 "Create", 68 func(receiver *models.Instance, _ sqlx.DBExecutor) error { 69 if overwrite != nil { 70 *receiver = *overwrite 71 } 72 return err 73 }, 74 ) 75 }