MCPcopy Create free account
hub / github.com/gogs/gogs / usersDeleteInactivated

Function usersDeleteInactivated

internal/database/users_test.go:674–718  ·  view source on GitHub ↗
(t *testing.T, ctx context.Context, s *UsersStore)

Source from the content-addressed store, hash-verified

672}
673
674func usersDeleteInactivated(t *testing.T, ctx context.Context, s *UsersStore) {
675 // User with repository ownership should be skipped
676 alice, err := s.Create(ctx, "alice", "alice@example.com", CreateUserOptions{})
677 require.NoError(t, err)
678 reposStore := newReposStore(s.db)
679 _, err = reposStore.Create(ctx, alice.ID, CreateRepoOptions{Name: "repo1"})
680 require.NoError(t, err)
681
682 // User with organization membership should be skipped
683 bob, err := s.Create(ctx, "bob", "bob@example.com", CreateUserOptions{})
684 require.NoError(t, err)
685 // TODO: Use Orgs.Create to replace SQL hack when the method is available.
686 org1, err := s.Create(ctx, "org1", "org1@example.com", CreateUserOptions{})
687 require.NoError(t, err)
688 err = s.db.Exec(
689 dbutil.Quote("UPDATE %s SET type = ? WHERE id IN (?)", "user"),
690 UserTypeOrganization, org1.ID,
691 ).Error
692 require.NoError(t, err)
693 // TODO: Use Orgs.Join to replace SQL hack when the method is available.
694 err = s.db.Exec(`INSERT INTO org_user (uid, org_id) VALUES (?, ?)`, bob.ID, org1.ID).Error
695 require.NoError(t, err)
696
697 // User activated state should be skipped
698 _, err = s.Create(ctx, "cindy", "cindy@example.com", CreateUserOptions{Activated: true})
699 require.NoError(t, err)
700
701 // User meant to be deleted
702 david, err := s.Create(ctx, "david", "david@example.com", CreateUserOptions{})
703 require.NoError(t, err)
704
705 tempSSHRootPath := filepath.Join(os.TempDir(), "usersDeleteInactivated-tempSSHRootPath")
706 conf.SetMockSSH(t, conf.SSHOpts{RootPath: tempSSHRootPath})
707
708 err = s.DeleteInactivated()
709 require.NoError(t, err)
710
711 _, err = s.GetByID(ctx, david.ID)
712 wantErr := ErrUserNotExist{errutil.Args{"userID": david.ID}}
713 assert.Equal(t, wantErr, err)
714
715 users, err := s.List(ctx, 1, 10)
716 require.NoError(t, err)
717 require.Len(t, users, 3)
718}
719
720func usersGetByEmail(t *testing.T, ctx context.Context, s *UsersStore) {
721 t.Run("empty email", func(t *testing.T) {

Callers

nothing calls this directly

Calls 9

QuoteFunction · 0.92
SetMockSSHFunction · 0.92
newReposStoreFunction · 0.85
ExecMethod · 0.80
DeleteInactivatedMethod · 0.80
GetByIDMethod · 0.65
ListMethod · 0.65
LenMethod · 0.65
CreateMethod · 0.45

Tested by

no test coverage detected