MCPcopy Index your code
hub / github.com/coder/coder / TestSuspendedPagination

Function TestSuspendedPagination

coderd/users_test.go:2781–2823  ·  view source on GitHub ↗

TestSuspendedPagination is when the after_id is a suspended record. The database query should still return the correct page, as the after_id is in a subquery that finds the record regardless of its status. This is mainly to confirm the db fake has the same behavior.

(t *testing.T)

Source from the content-addressed store, hash-verified

2779// is in a subquery that finds the record regardless of its status.
2780// This is mainly to confirm the db fake has the same behavior.
2781func TestSuspendedPagination(t *testing.T) {
2782 t.Parallel()
2783 t.Skip("This fails when two users are created at the exact same time. The reason is unknown... See: https://github.com/coder/coder/actions/runs/3057047622/jobs/4931863163")
2784 client := coderdtest.New(t, nil)
2785 coderdtest.CreateFirstUser(t, client)
2786
2787 ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
2788 t.Cleanup(cancel)
2789
2790 me, err := client.User(ctx, codersdk.Me)
2791 require.NoError(t, err)
2792 orgID := me.OrganizationIDs[0]
2793
2794 total := 10
2795 users := make([]codersdk.User, 0, total)
2796 // Create users
2797 for i := 0; i < total; i++ {
2798 email := fmt.Sprintf("%d@coder.com", i)
2799 username := fmt.Sprintf("user%d", i)
2800 user, err := client.CreateUserWithOrgs(ctx, codersdk.CreateUserRequestWithOrgs{
2801 Email: email,
2802 Username: username,
2803 Password: "MySecurePassword!",
2804 OrganizationIDs: []uuid.UUID{orgID},
2805 })
2806 require.NoError(t, err)
2807 users = append(users, user)
2808 }
2809 sortUsers(users)
2810 deletedUser := users[2]
2811 expected := users[3:8]
2812 _, err = client.UpdateUserStatus(ctx, deletedUser.ID.String(), codersdk.UserStatusSuspended)
2813 require.NoError(t, err, "suspend user")
2814
2815 page, err := client.Users(ctx, codersdk.UsersRequest{
2816 Pagination: codersdk.Pagination{
2817 Limit: len(expected),
2818 AfterID: deletedUser.ID,
2819 },
2820 })
2821 require.NoError(t, err)
2822 require.Equal(t, expected, page.Users, "expected page")
2823}
2824
2825func TestUserAutofillParameters(t *testing.T) {
2826 t.Parallel()

Callers

nothing calls this directly

Calls 11

NewFunction · 0.92
CreateFirstUserFunction · 0.92
sortUsersFunction · 0.85
SkipMethod · 0.80
CreateUserWithOrgsMethod · 0.80
CleanupMethod · 0.65
UserMethod · 0.65
UpdateUserStatusMethod · 0.65
UsersMethod · 0.65
StringMethod · 0.45
EqualMethod · 0.45

Tested by

no test coverage detected