@@ -636,6 +636,7 @@ mod tests {
636636 use crate :: index:: api:: CrateOwner ;
637637 use crate :: test:: {
638638 assert_cache_control, assert_redirect, assert_redirect_cached, wrapper, TestDatabase ,
639+ TestEnvironment ,
639640 } ;
640641 use anyhow:: { Context , Error } ;
641642 use kuchikiki:: traits:: TendrilSink ;
@@ -1270,6 +1271,25 @@ mod tests {
12701271 }
12711272 }
12721273
1274+ fn run_check_links (
1275+ env : & TestEnvironment ,
1276+ url : & str ,
1277+ extra : & str ,
1278+ should_contain_redirect : bool ,
1279+ ) {
1280+ let response = env. frontend ( ) . get ( url) . send ( ) . unwrap ( ) ;
1281+ assert ! ( response. status( ) . is_success( ) ) ;
1282+ check_links ( response. text ( ) . unwrap ( ) , false , should_contain_redirect) ;
1283+ // Same test with AJAX endpoint.
1284+ let response = env
1285+ . frontend ( )
1286+ . get ( & format ! ( "/-/menus/platforms{url}{extra}" ) )
1287+ . send ( )
1288+ . unwrap ( ) ;
1289+ assert ! ( response. status( ) . is_success( ) ) ;
1290+ check_links ( response. text ( ) . unwrap ( ) , true , should_contain_redirect) ;
1291+ }
1292+
12731293 wrapper ( |env| {
12741294 env. fake_release ( )
12751295 . name ( "dummy" )
@@ -1281,55 +1301,15 @@ mod tests {
12811301 . add_target ( "x86_64-pc-windows-msvc" )
12821302 . create ( ) ?;
12831303
1284- let response = env. frontend ( ) . get ( "/crate/dummy/0.4.0" ) . send ( ) ?;
1285- assert ! ( response. status( ) . is_success( ) ) ;
1286- check_links ( response. text ( ) ?, false , false ) ;
1287- // Same test with AJAX endpoint.
1288- let response = env
1289- . frontend ( )
1290- . get ( "/-/menus/platforms/crate/dummy/0.4.0" )
1291- . send ( ) ?;
1292- assert ! ( response. status( ) . is_success( ) ) ;
1293- check_links ( response. text ( ) ?, true , false ) ;
1294-
1295- let response = env. frontend ( ) . get ( "/dummy/latest/dummy" ) . send ( ) ?;
1296- assert ! ( response. status( ) . is_success( ) ) ;
1297- check_links ( response. text ( ) ?, false , true ) ;
1298- // Same test with AJAX endpoint.
1299- let response = env
1300- . frontend ( )
1301- . get ( "/-/menus/platforms/dummy/latest/dummy/" )
1302- . send ( ) ?;
1303- assert ! ( response. status( ) . is_success( ) ) ;
1304- check_links ( response. text ( ) ?, true , true ) ;
1305-
1306- let response = env
1307- . frontend ( )
1308- . get ( "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy" )
1309- . send ( ) ?;
1310- assert ! ( response. status( ) . is_success( ) ) ;
1311- check_links ( response. text ( ) ?, false , true ) ;
1312- // Same test with AJAX endpoint.
1313- let response = env
1314- . frontend ( )
1315- . get ( "/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/" )
1316- . send ( ) ?;
1317- assert ! ( response. status( ) . is_success( ) ) ;
1318- check_links ( response. text ( ) ?, true , true ) ;
1319-
1320- let response = env
1321- . frontend ( )
1322- . get ( "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html" )
1323- . send ( ) ?;
1324- assert ! ( response. status( ) . is_success( ) ) ;
1325- check_links ( response. text ( ) ?, false , true ) ;
1326- // Same test with AJAX endpoint.
1327- let response = env
1328- . frontend ( )
1329- . get ( "/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html" )
1330- . send ( ) ?;
1331- assert ! ( response. status( ) . is_success( ) ) ;
1332- check_links ( response. text ( ) ?, true , true ) ;
1304+ run_check_links ( env, "/crate/dummy/0.4.0" , "" , false ) ;
1305+ run_check_links ( env, "/dummy/latest/dummy" , "/" , true ) ;
1306+ run_check_links ( env, "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy" , "/" , true ) ;
1307+ run_check_links (
1308+ env,
1309+ "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html" ,
1310+ "/" ,
1311+ true ,
1312+ ) ;
13331313
13341314 Ok ( ( ) )
13351315 } ) ;
0 commit comments