Skip to content

Commit 23d7e73

Browse files
authored
tests: Use more doc comments to describe tests and test helpers (#5540)
1 parent 43d317b commit 23d7e73

File tree

5 files changed

+89
-105
lines changed

5 files changed

+89
-105
lines changed

src/tests/owners.rs

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ fn create_and_add_owner(
170170
user
171171
}
172172

173-
// Ensures that so long as at least one owner remains associated with the crate,
174-
// a user can still remove their own login as an owner
173+
/// Ensures that so long as at least one owner remains associated with the crate,
174+
/// a user can still remove their own login as an owner
175175
#[test]
176176
fn owners_can_remove_self() {
177177
let (app, _, user, token) = TestApp::init().with_token();
@@ -207,7 +207,7 @@ fn owners_can_remove_self() {
207207
);
208208
}
209209

210-
// Verify consistency when adidng or removing multiple owners in a single request.
210+
/// Verify consistency when adidng or removing multiple owners in a single request.
211211
#[test]
212212
fn modify_multiple_owners() {
213213
let (app, _, user, token) = TestApp::init().with_token();
@@ -406,13 +406,12 @@ fn invite_with_existing_expired_invite() {
406406
assert_eq!(2, app.as_inner().emails.mails_in_memory().unwrap().len());
407407
}
408408

409-
/* Testing the crate ownership between two crates and one team.
410-
Given two crates, one crate owned by both a team and a user,
411-
one only owned by a user, check that the CrateList returned
412-
for the user_id contains only the crates owned by that user,
413-
and that the CrateList returned for the team_id contains
414-
only crates owned by that team.
415-
*/
409+
/// Testing the crate ownership between two crates and one team.
410+
/// Given two crates, one crate owned by both a team and a user,
411+
/// one only owned by a user, check that the CrateList returned
412+
/// for the user_id contains only the crates owned by that user,
413+
/// and that the CrateList returned for the team_id contains
414+
/// only crates owned by that team.
416415
#[test]
417416
fn check_ownership_two_crates() {
418417
let (app, anon, user) = TestApp::init().with_user();
@@ -440,14 +439,13 @@ fn check_ownership_two_crates() {
440439
assert_eq!(json.crates[0].name, krate_owned_by_team.name);
441440
}
442441

443-
/* Given a crate owned by both a team and a user, check that the
444-
JSON returned by the /owner_team route and /owner_user route
445-
contains the correct kind of owner
446-
447-
Note that in this case function new_team must take a team name
448-
of form github:org_name:team_name as that is the format
449-
EncodableOwner::encodable is expecting
450-
*/
442+
/// Given a crate owned by both a team and a user, check that the
443+
/// JSON returned by the /owner_team route and /owner_user route
444+
/// contains the correct kind of owner
445+
///
446+
/// Note that in this case function new_team must take a team name
447+
/// of form github:org_name:team_name as that is the format
448+
/// EncodableOwner::encodable is expecting
451449
#[test]
452450
fn check_ownership_one_crate() {
453451
let (app, anon, user) = TestApp::init().with_user();
@@ -572,12 +570,11 @@ fn invitations_list_does_not_include_expired_invites_v1() {
572570
);
573571
}
574572

575-
/* Given a user inviting a different user to be a crate
576-
owner, check that the user invited can accept their
577-
invitation, the invitation will be deleted from
578-
the invitations table, and a new crate owner will be
579-
inserted into the table for the given crate.
580-
*/
573+
/// Given a user inviting a different user to be a crate
574+
/// owner, check that the user invited can accept their
575+
/// invitation, the invitation will be deleted from
576+
/// the invitations table, and a new crate owner will be
577+
/// inserted into the table for the given crate.
581578
#[test]
582579
fn test_accept_invitation() {
583580
let (app, anon, owner, owner_token) = TestApp::init().with_token();
@@ -600,11 +597,10 @@ fn test_accept_invitation() {
600597
assert_eq!(json.users.len(), 2);
601598
}
602599

603-
/* Given a user inviting a different user to be a crate
604-
owner, check that the user invited can decline their
605-
invitation and the invitation will be deleted from
606-
the invitations table.
607-
*/
600+
/// Given a user inviting a different user to be a crate
601+
/// owner, check that the user invited can decline their
602+
/// invitation and the invitation will be deleted from
603+
/// the invitations table.
608604
#[test]
609605
fn test_decline_invitation() {
610606
let (app, anon, owner, owner_token) = TestApp::init().with_token();
@@ -652,8 +648,8 @@ fn test_accept_invitation_by_mail() {
652648
assert_eq!(json.users.len(), 2);
653649
}
654650

655-
/// Hacky way to simulate the expiration of an ownership invitation. Instead of letting a month
656-
/// pass, the creation date of the invite is moved back a month.
651+
//// Hacky way to simulate the expiration of an ownership invitation. Instead of letting a month
652+
//// pass, the creation date of the invite is moved back a month.
657653
fn expire_invitation(app: &TestApp, crate_id: i32) {
658654
use cargo_registry::schema::crate_owner_invitations;
659655

src/tests/record.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ static IGNORED_HEADERS: &[&str] = &[
2929
"user-agent",
3030
];
3131

32-
// A "bomb" so when the test task exists we know when to shut down
33-
// the server and fail if the subtask failed.
32+
/// A "bomb" so when the test task exists we know when to shut down
33+
/// the server and fail if the subtask failed.
3434
pub struct Bomb {
3535
iorx: Sink,
3636
quittx: Option<oneshot::Sender<()>>,

src/tests/routes/crates/list.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -554,13 +554,12 @@ fn max_stable_version() {
554554
assert_eq!(json.crates[0].max_stable_version, Some("1.0.0".to_string()));
555555
}
556556

557-
/* Given two crates, one with downloads less than 90 days ago, the
558-
other with all downloads greater than 90 days ago, check that
559-
the order returned is by recent downloads, descending. Check
560-
also that recent download counts are returned in recent_downloads,
561-
and total downloads counts are returned in downloads, and that
562-
these numbers do not overlap.
563-
*/
557+
/// Given two crates, one with downloads less than 90 days ago, the
558+
/// other with all downloads greater than 90 days ago, check that
559+
/// the order returned is by recent downloads, descending. Check
560+
/// also that recent download counts are returned in recent_downloads,
561+
/// and total downloads counts are returned in downloads, and that
562+
/// these numbers do not overlap.
564563
#[test]
565564
fn test_recent_download_count() {
566565
let (app, anon, user) = TestApp::init().with_user();
@@ -595,10 +594,9 @@ fn test_recent_download_count() {
595594
assert_eq!(json.crates[1].downloads, 10);
596595
}
597596

598-
/* Given one crate with zero downloads, check that the crate
599-
still shows up in index results, but that it displays 0
600-
for both recent downloads and downloads.
601-
*/
597+
/// Given one crate with zero downloads, check that the crate
598+
/// still shows up in index results, but that it displays 0
599+
/// for both recent downloads and downloads.
602600
#[test]
603601
fn test_zero_downloads() {
604602
let (app, anon, user) = TestApp::init().with_user();
@@ -620,10 +618,9 @@ fn test_zero_downloads() {
620618
assert_eq!(json.crates[0].downloads, 0);
621619
}
622620

623-
/* Given two crates, one with more all-time downloads, the other with
624-
more downloads in the past 90 days, check that the index page for
625-
categories and keywords is sorted by recent downloads by default.
626-
*/
621+
/// Given two crates, one with more all-time downloads, the other with
622+
/// more downloads in the past 90 days, check that the index page for
623+
/// categories and keywords is sorted by recent downloads by default.
627624
#[test]
628625
fn test_default_sort_recent() {
629626
let (app, anon, user) = TestApp::init().with_user();

src/tests/team.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl crate::util::MockAnonymousUser {
1616
}
1717
}
1818

19-
// Test adding team without `github:`
19+
/// Test adding team without `github:`
2020
#[test]
2121
fn not_github() {
2222
let (app, _, user, token) = TestApp::init().with_token();
@@ -49,7 +49,7 @@ fn weird_name() {
4949
);
5050
}
5151

52-
// Test adding team without second `:`
52+
/// Test adding team without second `:`
5353
#[test]
5454
fn one_colon() {
5555
let (app, _, user, token) = TestApp::init().with_token();
@@ -82,7 +82,7 @@ fn nonexistent_team() {
8282
);
8383
}
8484

85-
// Test adding a renamed team
85+
/// Test adding a renamed team
8686
#[test]
8787
fn add_renamed_team() {
8888
let (app, anon) = TestApp::init().empty();
@@ -119,7 +119,7 @@ fn add_renamed_team() {
119119
assert_eq!(json.teams[0].login, "github:test-org:core");
120120
}
121121

122-
// Test adding team names with mixed case, when on the team
122+
/// Test adding team names with mixed case, when on the team
123123
#[test]
124124
fn add_team_mixed_case() {
125125
let (app, anon) = TestApp::init().empty();
@@ -174,7 +174,7 @@ fn add_team_as_org_owner() {
174174
assert_eq!(json.teams[0].login, "github:test-org:core");
175175
}
176176

177-
// Test adding team as owner when not on it
177+
/// Test adding team as owner when not on it
178178
#[test]
179179
fn add_team_as_non_member() {
180180
let (app, _) = TestApp::init().empty();
@@ -268,7 +268,7 @@ fn remove_team_as_team_owner() {
268268
);
269269
}
270270

271-
// Test trying to publish a crate we don't own
271+
/// Test trying to publish a crate we don't own
272272
#[test]
273273
fn publish_not_owned() {
274274
let (app, _) = TestApp::full().empty();
@@ -319,7 +319,7 @@ fn publish_org_owner_owned() {
319319
);
320320
}
321321

322-
// Test trying to publish a krate we do own (but only because of teams)
322+
/// Test trying to publish a krate we do own (but only because of teams)
323323
#[test]
324324
fn publish_owned() {
325325
let (app, _) = TestApp::full().empty();
@@ -340,7 +340,7 @@ fn publish_owned() {
340340
user_on_one_team.publish_crate(crate_to_publish).good();
341341
}
342342

343-
// Test trying to change owners (when only on an owning team)
343+
/// Test trying to change owners (when only on an owning team)
344344
#[test]
345345
fn add_owners_as_org_owner() {
346346
let (app, _) = TestApp::init().empty();

src/tests/user.rs

Lines changed: 40 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -374,16 +374,15 @@ fn updating_existing_user_doesnt_change_api_token() {
374374
assert_eq!("bar_token", user.gh_access_token);
375375
}
376376

377-
/* Given a GitHub user, check that if the user logs in,
378-
updates their email, logs out, then logs back in, the
379-
email they added to crates.io will not be overwritten
380-
by the information sent by GitHub.
381-
382-
This bug is problematic if the user's email preferences
383-
are set to private on GitHub, as GitHub will always
384-
send none as the email and we will end up inadvertently
385-
deleting their email when they sign back in.
386-
*/
377+
/// Given a GitHub user, check that if the user logs in,
378+
/// updates their email, logs out, then logs back in, the
379+
/// email they added to crates.io will not be overwritten
380+
/// by the information sent by GitHub.
381+
///
382+
/// This bug is problematic if the user's email preferences
383+
/// are set to private on GitHub, as GitHub will always
384+
/// send none as the email and we will end up inadvertently
385+
/// deleting their email when they sign back in.
387386
#[test]
388387
fn github_without_email_does_not_overwrite_email() {
389388
let (app, _) = TestApp::init().empty();
@@ -425,9 +424,8 @@ fn github_without_email_does_not_overwrite_email() {
425424
assert_eq!(json.user.email.unwrap(), "apricot@apricots.apricot");
426425
}
427426

428-
/* Given a new user, test that if they sign in with one email, change their email on GitHub, then
429-
sign in again, that the email in crates.io will remain set to the original email used on GitHub.
430-
*/
427+
/// Given a new user, test that if they sign in with one email, change their email on GitHub, then
428+
/// sign in again, that the email in crates.io will remain set to the original email used on GitHub.
431429
#[test]
432430
fn github_with_email_does_not_overwrite_email() {
433431
use cargo_registry::schema::emails;
@@ -461,10 +459,9 @@ fn github_with_email_does_not_overwrite_email() {
461459
assert_eq!(json.user.email, Some(original_email));
462460
}
463461

464-
/* Given a crates.io user, check that the user's email can be
465-
updated in the database (PUT /user/:user_id), then check
466-
that the updated email is sent back to the user (GET /me).
467-
*/
462+
/// Given a crates.io user, check that the user's email can be
463+
/// updated in the database (PUT /user/:user_id), then check
464+
/// that the updated email is sent back to the user (GET /me).
468465
#[test]
469466
fn test_email_get_and_put() {
470467
let (_app, _anon, user) = TestApp::init().with_user();
@@ -480,16 +477,15 @@ fn test_email_get_and_put() {
480477
assert!(json.user.email_verification_sent);
481478
}
482479

483-
/* Given a crates.io user, check to make sure that the user
484-
cannot add to the database an empty string or null as
485-
their email. If an attempt is made, update_user.rs will
486-
return an error indicating that an empty email cannot be
487-
added.
488-
489-
This is checked on the frontend already, but I'd like to
490-
make sure that a user cannot get around that and delete
491-
their email by adding an empty string.
492-
*/
480+
/// Given a crates.io user, check to make sure that the user
481+
/// cannot add to the database an empty string or null as
482+
/// their email. If an attempt is made, update_user.rs will
483+
/// return an error indicating that an empty email cannot be
484+
/// added.
485+
///
486+
/// This is checked on the frontend already, but I'd like to
487+
/// make sure that a user cannot get around that and delete
488+
/// their email by adding an empty string.
493489
#[test]
494490
fn test_empty_email_not_added() {
495491
let (_app, _anon, user) = TestApp::init().with_user();
@@ -510,12 +506,11 @@ fn test_empty_email_not_added() {
510506
);
511507
}
512508

513-
/* Check to make sure that neither other signed in users nor anonymous users can edit another
514-
user's email address.
515-
516-
If an attempt is made, update_user.rs will return an error indicating that the current user
517-
does not match the requested user.
518-
*/
509+
/// Check to make sure that neither other signed in users nor anonymous users can edit another
510+
/// user's email address.
511+
///
512+
/// If an attempt is made, update_user.rs will return an error indicating that the current user
513+
/// does not match the requested user.
519514
#[test]
520515
fn test_other_users_cannot_change_my_email() {
521516
let (app, anon, user) = TestApp::init().with_user();
@@ -543,12 +538,11 @@ fn test_other_users_cannot_change_my_email() {
543538
);
544539
}
545540

546-
/* Given a new user, test that their email can be added
547-
to the email table and a token for the email is generated
548-
and added to the token table. When /confirm/:email_token is
549-
requested, check that the response back is ok, and that
550-
the email_verified field on user is now set to true.
551-
*/
541+
/// Given a new user, test that their email can be added
542+
/// to the email table and a token for the email is generated
543+
/// and added to the token table. When /confirm/:email_token is
544+
/// requested, check that the response back is ok, and that
545+
/// the email_verified field on user is now set to true.
552546
#[test]
553547
fn test_confirm_user_email() {
554548
use cargo_registry::schema::emails;
@@ -585,10 +579,9 @@ fn test_confirm_user_email() {
585579
assert!(json.user.email_verification_sent);
586580
}
587581

588-
/* Given a user who existed before we added email confirmation,
589-
test that `email_verification_sent` is false so that we don't
590-
make the user think we've sent an email when we haven't.
591-
*/
582+
/// Given a user who existed before we added email confirmation,
583+
/// test that `email_verification_sent` is false so that we don't
584+
/// make the user think we've sent an email when we haven't.
592585
#[test]
593586
fn test_existing_user_email() {
594587
use cargo_registry::schema::emails;
@@ -638,9 +631,8 @@ fn test_user_owned_crates_doesnt_include_deleted_ownership() {
638631
assert_eq!(json.owned_crates.len(), 0);
639632
}
640633

641-
/* A user should be able to update the email notifications for crates they own. Only the crates that
642-
were sent in the request should be updated to the corresponding `email_notifications` value.
643-
*/
634+
/// A user should be able to update the email notifications for crates they own. Only the crates that
635+
/// were sent in the request should be updated to the corresponding `email_notifications` value.
644636
#[test]
645637
fn test_update_email_notifications() {
646638
let (app, _, user) = TestApp::init().with_user();
@@ -723,9 +715,8 @@ fn test_update_email_notifications() {
723715
})
724716
}
725717

726-
/* A user should not be able to update the `email_notifications` value for a crate that is not
727-
owned by them.
728-
*/
718+
/// A user should not be able to update the `email_notifications` value for a crate that is not
719+
/// owned by them.
729720
#[test]
730721
fn test_update_email_notifications_not_owned() {
731722
let (app, _, user) = TestApp::init().with_user();

0 commit comments

Comments
 (0)