@@ -13,6 +13,7 @@ use flate2::Compression;
1313use http:: StatusCode ;
1414use std:: collections:: HashMap ;
1515use std:: io:: Read ;
16+ use std:: iter:: FromIterator ;
1617use std:: time:: Duration ;
1718use std:: { io, thread} ;
1819
@@ -954,3 +955,36 @@ fn publish_rate_limit_doesnt_affect_existing_crates() {
954955 token. enqueue_publish ( new_version) . good ( ) ;
955956 app. run_pending_background_jobs ( ) ;
956957}
958+
959+ #[ test]
960+ fn features_version_2 ( ) {
961+ let ( app, _, user, token) = TestApp :: full ( ) . with_token ( ) ;
962+
963+ app. db ( |conn| {
964+ // Insert a crate directly into the database so that foo_new can depend on it
965+ CrateBuilder :: new ( "bar" , user. as_model ( ) . id ) . expect_build ( conn) ;
966+ } ) ;
967+
968+ let dependency = DependencyBuilder :: new ( "bar" ) ;
969+
970+ let crate_to_publish = PublishBuilder :: new ( "foo" )
971+ . version ( "1.0.0" )
972+ . dependency ( dependency)
973+ . feature ( "new_feat" , & [ "dep:bar" , "bar?/feat" ] )
974+ . feature ( "old_feat" , & [ ] ) ;
975+ token. enqueue_publish ( crate_to_publish) . good ( ) ;
976+ app. run_pending_background_jobs ( ) ;
977+
978+ let crates = app. crates_from_index_head ( "3/f/foo" ) ;
979+ assert_eq ! ( crates. len( ) , 1 ) ;
980+ assert_eq ! ( crates[ 0 ] . name, "foo" ) ;
981+ assert_eq ! ( crates[ 0 ] . deps. len( ) , 1 ) ;
982+ assert_eq ! ( crates[ 0 ] . v, Some ( 2 ) ) ;
983+ let features = HashMap :: from_iter ( [ ( "old_feat" . to_string ( ) , vec ! [ ] ) ] ) ;
984+ assert_eq ! ( crates[ 0 ] . features, features) ;
985+ let features2 = HashMap :: from_iter ( [ (
986+ "new_feat" . to_string ( ) ,
987+ vec ! [ "dep:bar" . to_string( ) , "bar?/feat" . to_string( ) ] ,
988+ ) ] ) ;
989+ assert_eq ! ( crates[ 0 ] . features2, Some ( features2) ) ;
990+ }
0 commit comments