@@ -1095,8 +1095,8 @@ func TestPaginatedUsers(t *testing.T) {
1095
1095
client := coderdtest .New (t , & coderdtest.Options {APIRateLimit : - 1 })
1096
1096
coderdtest .CreateFirstUser (t , client )
1097
1097
1098
- // This test can take longer than a long time.
1099
- ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong * 4 )
1098
+ // This test takes longer than a long time.
1099
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong * 2 )
1100
1100
defer cancel ()
1101
1101
1102
1102
me , err := client .User (ctx , codersdk .Me )
@@ -1153,25 +1153,41 @@ func TestPaginatedUsers(t *testing.T) {
1153
1153
sortUsers (allUsers )
1154
1154
sortUsers (specialUsers )
1155
1155
1156
- assertPagination (ctx , t , client , 10 , allUsers , nil )
1157
- assertPagination (ctx , t , client , 5 , allUsers , nil )
1158
- assertPagination (ctx , t , client , 3 , allUsers , nil )
1159
- assertPagination (ctx , t , client , 1 , allUsers , nil )
1160
-
1161
- // Try a search
1162
1156
gmailSearch := func (request codersdk.UsersRequest ) codersdk.UsersRequest {
1163
1157
request .Search = "gmail"
1164
1158
return request
1165
1159
}
1166
- assertPagination (ctx , t , client , 3 , specialUsers , gmailSearch )
1167
- assertPagination (ctx , t , client , 7 , specialUsers , gmailSearch )
1168
-
1169
1160
usernameSearch := func (request codersdk.UsersRequest ) codersdk.UsersRequest {
1170
1161
request .Search = "specialuser"
1171
1162
return request
1172
1163
}
1173
- assertPagination (ctx , t , client , 3 , specialUsers , usernameSearch )
1174
- assertPagination (ctx , t , client , 1 , specialUsers , usernameSearch )
1164
+
1165
+ tests := []struct {
1166
+ name string
1167
+ limit int
1168
+ allUsers []codersdk.User
1169
+ opt func (request codersdk.UsersRequest ) codersdk.UsersRequest
1170
+ }{
1171
+ {name : "all users" , limit : 10 , allUsers : allUsers },
1172
+ {name : "all users" , limit : 5 , allUsers : allUsers },
1173
+ {name : "all users" , limit : 3 , allUsers : allUsers },
1174
+ {name : "all users" , limit : 1 , allUsers : allUsers },
1175
+ {name : "gmail search" , limit : 3 , allUsers : specialUsers , opt : gmailSearch },
1176
+ {name : "gmail search" , limit : 7 , allUsers : specialUsers , opt : gmailSearch },
1177
+ {name : "username search" , limit : 3 , allUsers : specialUsers , opt : usernameSearch },
1178
+ {name : "username search" , limit : 3 , allUsers : specialUsers , opt : usernameSearch },
1179
+ }
1180
+ for _ , tt := range tests {
1181
+ tt := tt
1182
+ t .Run (fmt .Sprintf ("%s %d" , tt .name , tt .limit ), func (t * testing.T ) {
1183
+ t .Parallel ()
1184
+
1185
+ ctx , cancel := context .WithTimeout (context .Background (), testutil .WaitLong )
1186
+ defer cancel ()
1187
+
1188
+ assertPagination (ctx , t , client , tt .limit , tt .allUsers , tt .opt )
1189
+ })
1190
+ }
1175
1191
}
1176
1192
1177
1193
// Assert pagination will page through the list of all users using the given
@@ -1180,10 +1196,6 @@ func TestPaginatedUsers(t *testing.T) {
1180
1196
func assertPagination (ctx context.Context , t * testing.T , client * codersdk.Client , limit int , allUsers []codersdk.User ,
1181
1197
opt func (request codersdk.UsersRequest ) codersdk.UsersRequest ,
1182
1198
) {
1183
- // Ensure any single assertion doesn't take too long.s
1184
- ctx , cancel := context .WithTimeout (ctx , testutil .WaitLong )
1185
- defer cancel ()
1186
-
1187
1199
var count int
1188
1200
if opt == nil {
1189
1201
opt = func (request codersdk.UsersRequest ) codersdk.UsersRequest {
0 commit comments