@@ -636,6 +636,7 @@ mod tests {
636
636
use crate :: index:: api:: CrateOwner ;
637
637
use crate :: test:: {
638
638
assert_cache_control, assert_redirect, assert_redirect_cached, wrapper, TestDatabase ,
639
+ TestEnvironment ,
639
640
} ;
640
641
use anyhow:: { Context , Error } ;
641
642
use kuchikiki:: traits:: TendrilSink ;
@@ -1270,6 +1271,25 @@ mod tests {
1270
1271
}
1271
1272
}
1272
1273
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
+
1273
1293
wrapper ( |env| {
1274
1294
env. fake_release ( )
1275
1295
. name ( "dummy" )
@@ -1281,55 +1301,15 @@ mod tests {
1281
1301
. add_target ( "x86_64-pc-windows-msvc" )
1282
1302
. create ( ) ?;
1283
1303
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
+ ) ;
1333
1313
1334
1314
Ok ( ( ) )
1335
1315
} ) ;
0 commit comments