@@ -645,6 +645,7 @@ mod tests {
645
645
use crate :: index:: api:: CrateOwner ;
646
646
use crate :: test:: {
647
647
assert_cache_control, assert_redirect, assert_redirect_cached, wrapper, TestDatabase ,
648
+ TestEnvironment ,
648
649
} ;
649
650
use anyhow:: { Context , Error } ;
650
651
use kuchikiki:: traits:: TendrilSink ;
@@ -1279,6 +1280,25 @@ mod tests {
1279
1280
}
1280
1281
}
1281
1282
1283
+ fn run_check_links (
1284
+ env : & TestEnvironment ,
1285
+ url : & str ,
1286
+ extra : & str ,
1287
+ should_contain_redirect : bool ,
1288
+ ) {
1289
+ let response = env. frontend ( ) . get ( url) . send ( ) . unwrap ( ) ;
1290
+ assert ! ( response. status( ) . is_success( ) ) ;
1291
+ check_links ( response. text ( ) . unwrap ( ) , false , should_contain_redirect) ;
1292
+ // Same test with AJAX endpoint.
1293
+ let response = env
1294
+ . frontend ( )
1295
+ . get ( & format ! ( "/-/menus/platforms{url}{extra}" ) )
1296
+ . send ( )
1297
+ . unwrap ( ) ;
1298
+ assert ! ( response. status( ) . is_success( ) ) ;
1299
+ check_links ( response. text ( ) . unwrap ( ) , true , should_contain_redirect) ;
1300
+ }
1301
+
1282
1302
wrapper ( |env| {
1283
1303
env. fake_release ( )
1284
1304
. name ( "dummy" )
@@ -1290,55 +1310,15 @@ mod tests {
1290
1310
. add_target ( "x86_64-pc-windows-msvc" )
1291
1311
. create ( ) ?;
1292
1312
1293
- let response = env. frontend ( ) . get ( "/crate/dummy/0.4.0" ) . send ( ) ?;
1294
- assert ! ( response. status( ) . is_success( ) ) ;
1295
- check_links ( response. text ( ) ?, false , false ) ;
1296
- // Same test with AJAX endpoint.
1297
- let response = env
1298
- . frontend ( )
1299
- . get ( "/-/menus/platforms/crate/dummy/0.4.0" )
1300
- . send ( ) ?;
1301
- assert ! ( response. status( ) . is_success( ) ) ;
1302
- check_links ( response. text ( ) ?, true , false ) ;
1303
-
1304
- let response = env. frontend ( ) . get ( "/dummy/latest/dummy" ) . send ( ) ?;
1305
- assert ! ( response. status( ) . is_success( ) ) ;
1306
- check_links ( response. text ( ) ?, false , true ) ;
1307
- // Same test with AJAX endpoint.
1308
- let response = env
1309
- . frontend ( )
1310
- . get ( "/-/menus/platforms/dummy/latest/dummy/" )
1311
- . send ( ) ?;
1312
- assert ! ( response. status( ) . is_success( ) ) ;
1313
- check_links ( response. text ( ) ?, true , true ) ;
1314
-
1315
- let response = env
1316
- . frontend ( )
1317
- . get ( "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy" )
1318
- . send ( ) ?;
1319
- assert ! ( response. status( ) . is_success( ) ) ;
1320
- check_links ( response. text ( ) ?, false , true ) ;
1321
- // Same test with AJAX endpoint.
1322
- let response = env
1323
- . frontend ( )
1324
- . get ( "/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/" )
1325
- . send ( ) ?;
1326
- assert ! ( response. status( ) . is_success( ) ) ;
1327
- check_links ( response. text ( ) ?, true , true ) ;
1328
-
1329
- let response = env
1330
- . frontend ( )
1331
- . get ( "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html" )
1332
- . send ( ) ?;
1333
- assert ! ( response. status( ) . is_success( ) ) ;
1334
- check_links ( response. text ( ) ?, false , true ) ;
1335
- // Same test with AJAX endpoint.
1336
- let response = env
1337
- . frontend ( )
1338
- . get ( "/-/menus/platforms/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html" )
1339
- . send ( ) ?;
1340
- assert ! ( response. status( ) . is_success( ) ) ;
1341
- check_links ( response. text ( ) ?, true , true ) ;
1313
+ run_check_links ( env, "/crate/dummy/0.4.0" , "" , false ) ;
1314
+ run_check_links ( env, "/dummy/latest/dummy" , "/" , true ) ;
1315
+ run_check_links ( env, "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy" , "/" , true ) ;
1316
+ run_check_links (
1317
+ env,
1318
+ "/dummy/0.4.0/x86_64-pc-windows-msvc/dummy/struct.A.html" ,
1319
+ "/" ,
1320
+ true ,
1321
+ ) ;
1342
1322
1343
1323
Ok ( ( ) )
1344
1324
} ) ;
0 commit comments