Best Syzkaller code snippet using db.Delete
authority_test.go
Source:authority_test.go
...56 if c > 1 {57 t.Error("unexpected duplicated entries for role")58 }59 // clean up60 db.Where("name = ?", "role-a").Delete(authority.Role{})61}62func TestCreatePermission(t *testing.T) {63 auth := authority.New(authority.Options{64 TablesPrefix: "authority_",65 DB: db,66 })67 // test create permission68 err := auth.CreatePermission("permission-a")69 if err != nil {70 t.Error("an error was not expected while creating permision ", err)71 }72 var c int6473 res := db.Model(authority.Permission{}).Where("name = ?", "permission-a").Count(&c)74 if res.Error != nil {75 t.Error("unexpected error while storing permission: ", err)76 }77 if c == 0 {78 t.Error("permission has not been stored")79 }80 // test duplicated entries81 auth.CreatePermission("permission-a")82 auth.CreatePermission("permission-a")83 auth.CreatePermission("permission-a")84 db.Model(authority.Role{}).Where("name = ?", "permission-a").Count(&c)85 if c > 1 {86 t.Error("unexpected duplicated entries for permission")87 }88 // clean up89 db.Where("name = ?", "permission-a").Delete(authority.Permission{})90}91func TestAssignPermission(t *testing.T) {92 auth := authority.New(authority.Options{93 TablesPrefix: "authority_",94 DB: db,95 })96 // first create a role97 err := auth.CreateRole("role-a")98 if err != nil {99 t.Error("unexpected error while creating role.", err)100 }101 // second test create permissions102 err = auth.CreatePermission("permission-a")103 if err != nil {104 t.Error("unexpected error while creating permission to be assigned.", err)105 }106 err = auth.CreatePermission("permission-b")107 if err != nil {108 t.Error("unexpected error while creating permission to be assigned.", err)109 }110 // assign the permissions111 err = auth.AssignPermissions("role-a", []string{"permission-a", "permission-b"})112 if err != nil {113 t.Error("unexpected error while assigning permissions.", err)114 }115 // assign to missing role116 err = auth.AssignPermissions("role-aa", []string{"permission-a", "permission-b"})117 if err == nil {118 t.Error("expecting error when assigning to missing role")119 }120 // assign to missing permission121 err = auth.AssignPermissions("role-a", []string{"permission-aa"})122 if err == nil {123 t.Error("expecting error when assigning missing permission")124 }125 var r authority.Role126 db.Where("name = ?", "role-a").First(&r)127 var rolePermsCount int64128 db.Model(authority.RolePermission{}).Where("role_id = ?", r.ID).Count(&rolePermsCount)129 if rolePermsCount != 2 {130 t.Error("failed assigning roles to permission")131 }132 // clean up133 db.Where("role_id = ?", r.ID).Delete(authority.RolePermission{})134 db.Where("name = ?", "role-a").Delete(authority.Role{})135 db.Where("name = ?", "permission-a").Delete(authority.Permission{})136 db.Where("name = ?", "permission-b").Delete(authority.Permission{})137}138func TestAssignRole(t *testing.T) {139 auth := authority.New(authority.Options{140 TablesPrefix: "authority_",141 DB: db,142 })143 // first create a role144 err := auth.CreateRole("role-a")145 if err != nil {146 t.Error("unexpected error while creating role to be assigned.", err)147 }148 // assign the role149 err = auth.AssignRole(1, "role-a")150 if err != nil {151 t.Error("unexpected error while assigning role.", err)152 }153 // double assign the role154 err = auth.AssignRole(1, "role-a")155 if err == nil {156 t.Error("expecting an error when assign a role to user more than one time")157 }158 // assign a second role159 auth.CreateRole("role-b")160 err = auth.AssignRole(1, "role-b")161 if err != nil {162 t.Error("un expected error when assigning a second role. ", err)163 }164 // assign missing role165 err = auth.AssignRole(1, "role-aa")166 if err == nil {167 t.Error("expecting an error when assigning role to a user")168 }169 var r authority.Role170 db.Where("name = ?", "role-a").First(&r)171 var userRoles int64172 db.Model(authority.UserRole{}).Where("role_id = ?", r.ID).Count(&userRoles)173 if userRoles != 1 {174 t.Error("failed assigning roles to permission")175 }176 //clean up177 db.Where("user_id = ?", 1).Delete(authority.UserRole{})178 db.Where("name = ?", "role-a").Delete(authority.Role{})179 db.Where("name = ?", "role-b").Delete(authority.Role{})180}181func TestCheckRole(t *testing.T) {182 auth := authority.New(authority.Options{183 TablesPrefix: "authority_",184 DB: db,185 })186 // first create a role and assign it to a user187 err := auth.CreateRole("role-a")188 if err != nil {189 t.Error("unexpected error while creating role to be assigned.", err)190 }191 // assign the role192 err = auth.AssignRole(1, "role-a")193 if err != nil {194 t.Error("unexpected error while assigning role.", err)195 }196 // assert197 ok, err := auth.CheckRole(1, "role-a")198 if err != nil {199 t.Error("unexpected error while checking user for assigned role.", err)200 }201 if !ok {202 t.Error("failed to check assinged role")203 }204 // check aa missing role205 _, err = auth.CheckRole(1, "role-aa")206 if err == nil {207 t.Error("expecting an error when checking a missing role")208 }209 // check a missing user210 ok, _ = auth.CheckRole(11, "role-a")211 if ok {212 t.Error("expecting false when checking missing role")213 }214 // clean up215 var r authority.Role216 db.Where("name = ?", "role-a").First(&r)217 db.Where("role_id = ?", r.ID).Delete(authority.UserRole{})218 db.Where("name = ?", "role-a").Delete(authority.Role{})219}220func TestCheckPermission(t *testing.T) {221 auth := authority.New(authority.Options{222 TablesPrefix: "authority_",223 DB: db,224 })225 // first create a role226 err := auth.CreateRole("role-a")227 if err != nil {228 t.Error("unexpected error while creating role.", err)229 }230 //create permissions231 err = auth.CreatePermission("permission-a")232 if err != nil {233 t.Error("unexpected error while creating permission to be assigned.", err)234 }235 err = auth.CreatePermission("permission-b")236 if err != nil {237 t.Error("unexpected error while creating permission to be assigned.", err)238 }239 // assign the permissions240 err = auth.AssignPermissions("role-a", []string{"permission-a", "permission-b"})241 if err != nil {242 t.Error("unexpected error while assigning permissions.", err)243 }244 // test when no role is a ssigned245 ok, err := auth.CheckPermission(1, "permission-a")246 if err != nil {247 t.Error("expecting error to be nil when no role is assigned")248 }249 if ok {250 t.Error("expecting false to be returned when no role is assigned")251 }252 // assign the role253 err = auth.AssignRole(1, "role-a")254 if err != nil {255 t.Error("unexpected error while assigning role.", err)256 }257 // test a permission of an assigned role258 ok, err = auth.CheckPermission(1, "permission-a")259 if err != nil {260 t.Error("unexpected error while checking permission of a user.", err)261 }262 if !ok {263 t.Error("expecting true to be returned")264 }265 // check when user does not have roles266 ok, _ = auth.CheckPermission(111, "permission-a")267 if ok {268 t.Error("expecting an false when checking permission of not assigned user")269 }270 // test assigning missing permission271 _, err = auth.CheckPermission(1, "permission-aa")272 if err == nil {273 t.Error("expecting an error when checking a missing permission")274 }275 // check for an exist but not assigned permission276 auth.CreatePermission("permission-c")277 ok, _ = auth.CheckPermission(1, "permission-c")278 if ok {279 t.Error("expecting false when checking for not assigned permissions")280 }281 // clean up282 var r authority.Role283 db.Where("name = ?", "role-a").First(&r)284 db.Where("role_id = ?", r.ID).Delete(authority.UserRole{})285 db.Where("role_id = ?", r.ID).Delete(authority.RolePermission{})286 db.Where("name = ?", "permission-a").Delete(authority.Permission{})287 db.Where("name = ?", "permission-b").Delete(authority.Permission{})288 db.Where("name = ?", "permission-c").Delete(authority.Permission{})289 db.Where("name = ?", "role-a").Delete(authority.Role{})290}291func TestCheckRolePermission(t *testing.T) {292 auth := authority.New(authority.Options{293 TablesPrefix: "authority_",294 DB: db,295 })296 // first create a role297 err := auth.CreateRole("role-a")298 if err != nil {299 t.Error("unexpected error while creating role.", err)300 }301 // second test create permissions302 err = auth.CreatePermission("permission-a")303 if err != nil {304 t.Error("unexpected error while creating permission to be assigned.", err)305 }306 err = auth.CreatePermission("permission-b")307 if err != nil {308 t.Error("unexpected error while creating permission to be assigned.", err)309 }310 // third assign the permissions311 err = auth.AssignPermissions("role-a", []string{"permission-a", "permission-b"})312 if err != nil {313 t.Error("unexpected error while assigning permissions.", err)314 }315 // check the role permission316 ok, err := auth.CheckRolePermission("role-a", "permission-a")317 if err != nil {318 t.Error("unexpected error while checking role permission.", err)319 }320 if !ok {321 t.Error("failed assigning roles to permission check")322 }323 // check a missing role324 _, err = auth.CheckRolePermission("role-aa", "permission-a")325 if err == nil {326 t.Error("expecting an error when checking permisson of missing role")327 }328 // check with missing permission329 _, err = auth.CheckRolePermission("role-a", "permission-aa")330 if err == nil {331 t.Error("expecting an error when checking missing permission")332 }333 // check with not assigned permission334 auth.CreatePermission("permission-c")335 ok, _ = auth.CheckRolePermission("role-a", "permission-c")336 if ok {337 t.Error("expecting false when checking a missing permission")338 }339 //clean up340 var r authority.Role341 db.Where("name = ?", "role-a").First(&r)342 db.Where("role_id = ?", r.ID).Delete(authority.RolePermission{})343 db.Where("name = ?", "permission-a").Delete(authority.Permission{})344 db.Where("name = ?", "permission-b").Delete(authority.Permission{})345 db.Where("name = ?", "permission-c").Delete(authority.Permission{})346 db.Where("name = ?", "role-a").Delete(authority.Role{})347}348func TestRevokeRole(t *testing.T) {349 auth := authority.New(authority.Options{350 TablesPrefix: "authority_",351 DB: db,352 })353 // first create a role354 err := auth.CreateRole("role-a")355 if err != nil {356 t.Error("unexpected error while creating role.", err)357 }358 // assign the role359 err = auth.AssignRole(1, "role-a")360 if err != nil {361 t.Error("unexpected error while assigning role.", err)362 }363 //test364 err = auth.RevokeRole(1, "role-a")365 if err != nil {366 t.Error("unexpected error revoking user role.", err)367 }368 // revoke missing role369 err = auth.RevokeRole(1, "role-aa")370 if err == nil {371 t.Error("expecting error when revoking a missing role")372 }373 var c int64374 db.Model(authority.UserRole{}).Where("user_id = ?", 1).Count(&c)375 if c != 0 {376 t.Error("failed assert revoking user role")377 }378 var r authority.Role379 db.Where("name = ?", "role-a").First(&r)380 db.Where("role_id = ?", r.ID).Delete(authority.UserRole{})381 db.Where("name = ?", "role-a").Delete(authority.Role{})382}383func TestRevokePermission(t *testing.T) {384 auth := authority.New(authority.Options{385 TablesPrefix: "authority_",386 DB: db,387 })388 // first create a role389 err := auth.CreateRole("role-a")390 if err != nil {391 t.Error("unexpected error while creating role.", err)392 }393 // second test create permissions394 err = auth.CreatePermission("permission-a")395 if err != nil {396 t.Error("unexpected error while creating permission to be assigned.", err)397 }398 err = auth.CreatePermission("permission-b")399 if err != nil {400 t.Error("unexpected error while creating permission to be assigned.", err)401 }402 // third assign the permissions403 err = auth.AssignPermissions("role-a", []string{"permission-a", "permission-b"})404 if err != nil {405 t.Error("unexpected error while assigning permissions.", err)406 }407 // assign the role408 err = auth.AssignRole(1, "role-a")409 if err != nil {410 t.Error("unexpected error while assigning role.", err)411 }412 // case: user not assigned role413 err = auth.RevokePermission(11, "permission-a")414 if err != nil {415 t.Error("expecting error to be nil", err)416 }417 // test418 err = auth.RevokePermission(1, "permission-a")419 if err != nil {420 t.Error("unexpected error while revoking role permissions.", err)421 }422 // revoke missing permissin423 err = auth.RevokePermission(1, "permission-aa")424 if err == nil {425 t.Error("expecting error when revoking a missing permission")426 }427 // assert, count assigned permission, should be one428 var r authority.Role429 db.Where("name = ?", "role-a").First(&r)430 var c int64431 db.Model(authority.RolePermission{}).Where("role_id = ?", r.ID).Count(&c)432 if c != 1 {433 t.Error("failed assert revoking permission role")434 }435 // clean up436 db.Where("role_id = ?", r.ID).Delete(authority.UserRole{})437 db.Where("role_id = ?", r.ID).Delete(authority.RolePermission{})438 db.Where("name = ?", "permission-a").Delete(authority.Permission{})439 db.Where("name = ?", "permission-b").Delete(authority.Permission{})440 db.Where("name = ?", "role-a").Delete(authority.Role{})441}442func TestRevokeRolePermission(t *testing.T) {443 auth := authority.New(authority.Options{444 TablesPrefix: "authority_",445 DB: db,446 })447 // first create a role448 err := auth.CreateRole("role-a")449 if err != nil {450 t.Error("unexpected error while creating role.", err)451 }452 // second test create permissions453 err = auth.CreatePermission("permission-a")454 if err != nil {455 t.Error("unexpected error while creating permission to be assigned.", err)456 }457 err = auth.CreatePermission("permission-b")458 if err != nil {459 t.Error("unexpected error while creating permission to be assigned.", err)460 }461 // third assign the permissions462 err = auth.AssignPermissions("role-a", []string{"permission-a", "permission-b"})463 if err != nil {464 t.Error("unexpected error while assigning permissions.", err)465 }466 // test revoke missing role467 err = auth.RevokeRolePermission("role-aa", "permission-a")468 if err == nil {469 t.Error("expecting an error when revoking a missing role")470 }471 // test revoke missing permission472 err = auth.RevokeRolePermission("role-a", "permission-aa")473 if err == nil {474 t.Error("expecting an error when revoking a missing permission")475 }476 err = auth.RevokeRolePermission("role-a", "permission-a")477 if err != nil {478 t.Error("unexpected error while revoking role permissions.", err)479 }480 // assert, count assigned permission, should be one481 var r authority.Role482 db.Where("name = ?", "role-a").First(&r)483 var c int64484 db.Model(authority.RolePermission{}).Where("role_id = ?", r.ID).Count(&c)485 if c != 1 {486 t.Error("failed assert revoking permission role")487 }488 // clean up489 db.Where("role_id = ?", r.ID).Delete(authority.RolePermission{})490 db.Where("name = ?", "permission-a").Delete(authority.Permission{})491 db.Where("name = ?", "permission-b").Delete(authority.Permission{})492 db.Where("name = ?", "role-a").Delete(authority.Role{})493}494func TestGetRoles(t *testing.T) {495 auth := authority.New(authority.Options{496 TablesPrefix: "authority_",497 DB: db,498 })499 // first create roles500 err := auth.CreateRole("role-a")501 if err != nil {502 t.Error("unexpected error while creating role.", err)503 }504 err = auth.CreateRole("role-b")505 if err != nil {506 t.Error("unexpected error while creating role.", err)507 }508 // test509 roles, err := auth.GetRoles()510 // check511 if len(roles) != 2 {512 t.Error("failed assert getting roles")513 }514 db.Where("name = ?", "role-a").Delete(authority.Role{})515 db.Where("name = ?", "role-b").Delete(authority.Role{})516}517func TestGetPermissions(t *testing.T) {518 auth := authority.New(authority.Options{519 TablesPrefix: "authority_",520 DB: db,521 })522 // first create permission523 err := auth.CreatePermission("permission-a")524 if err != nil {525 t.Error("unexpected error while creating permission.", err)526 }527 err = auth.CreatePermission("permission-b")528 if err != nil {529 t.Error("unexpected error while creating permission.", err)530 }531 // test532 perms, err := auth.GetPermissions()533 // check534 if len(perms) != 2 {535 t.Error("failed assert getting permission")536 }537 db.Where("name = ?", "permission-a").Delete(authority.Permission{})538 db.Where("name = ?", "permission-b").Delete(authority.Permission{})539}540func TestDeleteRole(t *testing.T) {541 auth := authority.New(authority.Options{542 TablesPrefix: "authority_",543 DB: db,544 })545 err := auth.CreateRole("role-a")546 if err != nil {547 t.Error("unexpected error while creating role.", err)548 }549 // test delete a missing role550 err = auth.DeleteRole("role-aa")551 if err == nil {552 t.Error("expecting an error when deleting a missing role")553 }554 // test delete an assigned role555 auth.AssignRole(1, "role-a")556 err = auth.DeleteRole("role-a")557 if err == nil {558 t.Error("expecting an error when deleting an assigned role")559 }560 auth.RevokeRole(1, "role-a")561 err = auth.DeleteRole("role-a")562 if err != nil {563 t.Error("unexpected error while deleting role.", err)564 }565 var c int64566 db.Model(authority.Role{}).Count(&c)567 if c != 0 {568 t.Error("failed assert deleting role")569 }570}571func TestDeletePermission(t *testing.T) {572 auth := authority.New(authority.Options{573 TablesPrefix: "authority_",574 DB: db,575 })576 err := auth.CreatePermission("permission-a")577 if err != nil {578 t.Error("unexpected error while creating permission.", err)579 }580 // delete missing permission581 err = auth.DeletePermission("permission-aa")582 if err == nil {583 t.Error("expecting an error when deleting a missing permission")584 }585 // delete an assigned permission586 auth.CreateRole("role-a")587 auth.AssignPermissions("role-a", []string{"permission-a"})588 // delete assinged permission589 err = auth.DeletePermission("permission-a")590 if err == nil {591 t.Error("expecting an error when deleting assigned permission")592 }593 auth.RevokeRolePermission("role-a", "permission-a")594 err = auth.DeletePermission("permission-a")595 if err != nil {596 t.Error("unexpected error while deleting permission.", err)597 }598 var c int64599 db.Model(authority.Permission{}).Count(&c)600 if c != 0 {601 t.Error("failed assert deleting permission")602 }603 // clean up604 auth.DeleteRole("role-a")605}606func TestGetUserRoles(t *testing.T) {607 auth := authority.New(authority.Options{608 TablesPrefix: "authority_",609 DB: db,610 })611 // first create a role612 auth.CreateRole("role-a")613 auth.CreateRole("role-b")614 auth.AssignRole(1, "role-a")615 auth.AssignRole(1, "role-b")616 roles, _ := auth.GetUserRoles(1)617 if len(roles) != 2 {618 t.Error("expeting two roles to be returned")619 }620 if !sliceHasString(roles, "role-a") {621 t.Error("missing role in returned roles")622 }623 if !sliceHasString(roles, "role-b") {624 t.Error("missing role in returned roles")625 }626 db.Where("user_id = ?", 1).Delete(authority.UserRole{})627 db.Where("name = ?", "role-a").Delete(authority.Role{})628 db.Where("name = ?", "role-b").Delete(authority.Role{})629}630func sliceHasString(s []string, val string) bool {631 for _, v := range s {632 if v == val {633 return true634 }635 }636 return false637}...
dbrestore.go
Source:dbrestore.go
...31type DbRestoreInterface interface {32 Create(ctx context.Context, dbRestore *v1beta1.DbRestore, opts v1.CreateOptions) (*v1beta1.DbRestore, error)33 Update(ctx context.Context, dbRestore *v1beta1.DbRestore, opts v1.UpdateOptions) (*v1beta1.DbRestore, error)34 UpdateStatus(ctx context.Context, dbRestore *v1beta1.DbRestore, opts v1.UpdateOptions) (*v1beta1.DbRestore, error)35 Delete(ctx context.Context, name string, opts v1.DeleteOptions) error36 DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error37 Get(ctx context.Context, name string, opts v1.GetOptions) (*v1beta1.DbRestore, error)38 List(ctx context.Context, opts v1.ListOptions) (*v1beta1.DbRestoreList, error)39 Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error)40 Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.DbRestore, err error)41 DbRestoreExpansion42}43// dbRestores implements DbRestoreInterface44type dbRestores struct {45 client rest.Interface46 ns string47}48// newDbRestores returns a DbRestores49func newDbRestores(c *QuchengV1beta1Client, namespace string) *dbRestores {50 return &dbRestores{51 client: c.RESTClient(),52 ns: namespace,53 }54}55// Get takes name of the dbRestore, and returns the corresponding dbRestore object, and an error if there is any.56func (c *dbRestores) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.DbRestore, err error) {57 result = &v1beta1.DbRestore{}58 err = c.client.Get().59 Namespace(c.ns).60 Resource("dbrestores").61 Name(name).62 VersionedParams(&options, scheme.ParameterCodec).63 Do(ctx).64 Into(result)65 return66}67// List takes label and field selectors, and returns the list of DbRestores that match those selectors.68func (c *dbRestores) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.DbRestoreList, err error) {69 var timeout time.Duration70 if opts.TimeoutSeconds != nil {71 timeout = time.Duration(*opts.TimeoutSeconds) * time.Second72 }73 result = &v1beta1.DbRestoreList{}74 err = c.client.Get().75 Namespace(c.ns).76 Resource("dbrestores").77 VersionedParams(&opts, scheme.ParameterCodec).78 Timeout(timeout).79 Do(ctx).80 Into(result)81 return82}83// Watch returns a watch.Interface that watches the requested dbRestores.84func (c *dbRestores) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) {85 var timeout time.Duration86 if opts.TimeoutSeconds != nil {87 timeout = time.Duration(*opts.TimeoutSeconds) * time.Second88 }89 opts.Watch = true90 return c.client.Get().91 Namespace(c.ns).92 Resource("dbrestores").93 VersionedParams(&opts, scheme.ParameterCodec).94 Timeout(timeout).95 Watch(ctx)96}97// Create takes the representation of a dbRestore and creates it. Returns the server's representation of the dbRestore, and an error, if there is any.98func (c *dbRestores) Create(ctx context.Context, dbRestore *v1beta1.DbRestore, opts v1.CreateOptions) (result *v1beta1.DbRestore, err error) {99 result = &v1beta1.DbRestore{}100 err = c.client.Post().101 Namespace(c.ns).102 Resource("dbrestores").103 VersionedParams(&opts, scheme.ParameterCodec).104 Body(dbRestore).105 Do(ctx).106 Into(result)107 return108}109// Update takes the representation of a dbRestore and updates it. Returns the server's representation of the dbRestore, and an error, if there is any.110func (c *dbRestores) Update(ctx context.Context, dbRestore *v1beta1.DbRestore, opts v1.UpdateOptions) (result *v1beta1.DbRestore, err error) {111 result = &v1beta1.DbRestore{}112 err = c.client.Put().113 Namespace(c.ns).114 Resource("dbrestores").115 Name(dbRestore.Name).116 VersionedParams(&opts, scheme.ParameterCodec).117 Body(dbRestore).118 Do(ctx).119 Into(result)120 return121}122// UpdateStatus was generated because the type contains a Status member.123// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().124func (c *dbRestores) UpdateStatus(ctx context.Context, dbRestore *v1beta1.DbRestore, opts v1.UpdateOptions) (result *v1beta1.DbRestore, err error) {125 result = &v1beta1.DbRestore{}126 err = c.client.Put().127 Namespace(c.ns).128 Resource("dbrestores").129 Name(dbRestore.Name).130 SubResource("status").131 VersionedParams(&opts, scheme.ParameterCodec).132 Body(dbRestore).133 Do(ctx).134 Into(result)135 return136}137// Delete takes name of the dbRestore and deletes it. Returns an error if one occurs.138func (c *dbRestores) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error {139 return c.client.Delete().140 Namespace(c.ns).141 Resource("dbrestores").142 Name(name).143 Body(&opts).144 Do(ctx).145 Error()146}147// DeleteCollection deletes a collection of objects.148func (c *dbRestores) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error {149 var timeout time.Duration150 if listOpts.TimeoutSeconds != nil {151 timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second152 }153 return c.client.Delete().154 Namespace(c.ns).155 Resource("dbrestores").156 VersionedParams(&listOpts, scheme.ParameterCodec).157 Timeout(timeout).158 Body(&opts).159 Do(ctx).160 Error()161}162// Patch applies the patch and returns the patched dbRestore.163func (c *dbRestores) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.DbRestore, err error) {164 result = &v1beta1.DbRestore{}165 err = c.client.Patch(pt).166 Namespace(c.ns).167 Resource("dbrestores")....
policy.go
Source:policy.go
...25// Update updates policy by the policy identifier.26func (p *policies) Update(ctx context.Context, policy *v1.Policy, opts metav1.UpdateOptions) error {27 return p.db.Save(policy).Error28}29// Delete deletes the policy by the policy identifier.30func (p *policies) Delete(ctx context.Context, username, name string, opts metav1.DeleteOptions) error {31 if opts.Unscoped {32 p.db = p.db.Unscoped()33 }34 err := p.db.Where("username = ? and name = ?", username, name).Delete(&v1.Policy{}).Error35 if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {36 return errors.WithCode(code.ErrDatabase, err.Error())37 }38 return nil39}40// DeleteByUser deletes policies by username.41func (p *policies) DeleteByUser(ctx context.Context, username string, opts metav1.DeleteOptions) error {42 if opts.Unscoped {43 p.db = p.db.Unscoped()44 }45 return p.db.Where("username = ?", username).Delete(&v1.Policy{}).Error46}47// DeleteCollection batch deletes policies by policies ids.48func (p *policies) DeleteCollection(49 ctx context.Context,50 username string,51 names []string,52 opts metav1.DeleteOptions,53) error {54 if opts.Unscoped {55 p.db = p.db.Unscoped()56 }57 return p.db.Where("username = ? and name in (?)", username, names).Delete(&v1.Policy{}).Error58}59// DeleteCollectionByUser batch deletes policies usernames.60func (p *policies) DeleteCollectionByUser(ctx context.Context, usernames []string, opts metav1.DeleteOptions) error {61 if opts.Unscoped {62 p.db = p.db.Unscoped()63 }64 return p.db.Where("username in (?)", usernames).Delete(&v1.Policy{}).Error65}66// Get return policy by the policy identifier.67func (p *policies) Get(ctx context.Context, username, name string, opts metav1.GetOptions) (*v1.Policy, error) {68 policy := &v1.Policy{}69 err := p.db.Where("username = ? and name = ?", username, name).First(&policy).Error70 if err != nil {71 if errors.Is(err, gorm.ErrRecordNotFound) {72 return nil, errors.WithCode(code.ErrPolicyNotFound, err.Error())73 }74 return nil, errors.WithCode(code.ErrDatabase, err.Error())75 }76 return policy, nil77}78// List return all policies....
Delete
Using AI Code Generation
1import (2func main() {3 db, err := bolt.Open("my.db", 0600, nil)4 if err != nil {5 log.Fatal(err)6 }7 defer db.Close()8 err = db.Update(func(tx *bolt.Tx) error {9 err := tx.Bucket([]byte("bar")).Delete([]byte("foo"))10 })11 if err != nil {12 log.Fatal(err)13 }14 err = db.View(func(tx *bolt.Tx) error {15 v := tx.Bucket([]byte("bar")).Get([]byte("foo"))16 fmt.Printf("The answer is: %s17 })18 if err != nil {19 log.Fatal(err)20 }21}22import (23func main() {24 db, err := bolt.Open("my.db", 0600, nil)25 if err != nil {26 log.Fatal(err)27 }28 defer db.Close()29 err = db.Update(func(tx *bolt.Tx) error {30 err := tx.DeleteBucket([]byte("foo"))31 })32 if err != nil {33 log.Fatal(err)34 }35 err = db.View(func(tx *bolt.Tx) error {36 v := tx.Bucket([]byte("bar")).Get([]byte("foo"))37 fmt.Printf("The answer is: %s38 })39 if err != nil {40 log.Fatal(err)41 }42}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!