(t *testing.T, ctx context.Context, s *UsersStore)
| 672 | } |
| 673 | |
| 674 | func 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 | |
| 720 | func usersGetByEmail(t *testing.T, ctx context.Context, s *UsersStore) { |
| 721 | t.Run("empty email", func(t *testing.T) { |
nothing calls this directly
no test coverage detected