@@ -5,6 +5,7 @@ use crates_io::rate_limiter::LimitedAction;
55use crates_io:: schema:: { publish_limit_buckets, publish_rate_overrides} ;
66use diesel:: { ExpressionMethods , RunQueryDsl } ;
77use http:: StatusCode ;
8+ use insta:: assert_snapshot;
89use std:: thread;
910use std:: time:: Duration ;
1011
@@ -65,7 +66,10 @@ async fn publish_new_crate_ratelimit_expires() {
6566 let crate_to_publish = PublishBuilder :: new ( "rate_limited" , "1.0.0" ) ;
6667 token. publish_crate ( crate_to_publish) . await . good ( ) ;
6768
68- assert_eq ! ( app. stored_files( ) . await . len( ) , 2 ) ;
69+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
70+ crates/rate_limited/rate_limited-1.0.0.crate
71+ index/ra/te/rate_limited
72+ "### ) ;
6973
7074 let json = anon. show_crate ( "rate_limited" ) . await ;
7175 assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
@@ -98,15 +102,23 @@ async fn publish_new_crate_override_loosens_ratelimit() {
98102 let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.0" ) ;
99103 token. publish_crate ( crate_to_publish) . await . good ( ) ;
100104
101- assert_eq ! ( app. stored_files( ) . await . len( ) , 2 ) ;
105+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
106+ crates/rate_limited1/rate_limited1-1.0.0.crate
107+ index/ra/te/rate_limited1
108+ "### ) ;
102109
103110 let json = anon. show_crate ( "rate_limited1" ) . await ;
104111 assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
105112
106113 let crate_to_publish = PublishBuilder :: new ( "rate_limited2" , "1.0.0" ) ;
107114 token. publish_crate ( crate_to_publish) . await . good ( ) ;
108115
109- assert_eq ! ( app. stored_files( ) . await . len( ) , 4 ) ;
116+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
117+ crates/rate_limited1/rate_limited1-1.0.0.crate
118+ crates/rate_limited2/rate_limited2-1.0.0.crate
119+ index/ra/te/rate_limited1
120+ index/ra/te/rate_limited2
121+ "### ) ;
110122
111123 let json = anon. show_crate ( "rate_limited2" ) . await ;
112124 assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
@@ -117,7 +129,12 @@ async fn publish_new_crate_override_loosens_ratelimit() {
117129 . await
118130 . assert_rate_limited ( LimitedAction :: PublishNew ) ;
119131
120- assert_eq ! ( app. stored_files( ) . await . len( ) , 4 ) ;
132+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
133+ crates/rate_limited1/rate_limited1-1.0.0.crate
134+ crates/rate_limited2/rate_limited2-1.0.0.crate
135+ index/ra/te/rate_limited1
136+ index/ra/te/rate_limited2
137+ "### ) ;
121138
122139 let response = anon. get :: < ( ) > ( "/api/v1/crates/rate_limited3" ) . await ;
123140 assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
@@ -151,7 +168,10 @@ async fn publish_new_crate_expired_override_ignored() {
151168 let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.0" ) ;
152169 token. publish_crate ( crate_to_publish) . await . good ( ) ;
153170
154- assert_eq ! ( app. stored_files( ) . await . len( ) , 2 ) ;
171+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
172+ crates/rate_limited1/rate_limited1-1.0.0.crate
173+ index/ra/te/rate_limited1
174+ "### ) ;
155175
156176 let json = anon. show_crate ( "rate_limited1" ) . await ;
157177 assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
@@ -162,7 +182,10 @@ async fn publish_new_crate_expired_override_ignored() {
162182 . await
163183 . assert_rate_limited ( LimitedAction :: PublishNew ) ;
164184
165- assert_eq ! ( app. stored_files( ) . await . len( ) , 2 ) ;
185+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
186+ crates/rate_limited1/rate_limited1-1.0.0.crate
187+ index/ra/te/rate_limited1
188+ "### ) ;
166189
167190 let response = anon. get :: < ( ) > ( "/api/v1/crates/rate_limited2" ) . await ;
168191 assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
@@ -194,15 +217,22 @@ async fn publish_existing_crate_rate_limited() {
194217
195218 let json = anon. show_crate ( "rate_limited1" ) . await ;
196219 assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
197- assert_eq ! ( app. stored_files( ) . await . len( ) , 2 ) ;
220+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
221+ crates/rate_limited1/rate_limited1-1.0.0.crate
222+ index/ra/te/rate_limited1
223+ "### ) ;
198224
199225 // Uploading the first update to the crate works
200226 let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.1" ) ;
201227 token. publish_crate ( crate_to_publish) . await . good ( ) ;
202228
203229 let json = anon. show_crate ( "rate_limited1" ) . await ;
204230 assert_eq ! ( json. krate. max_version, "1.0.1" ) ;
205- assert_eq ! ( app. stored_files( ) . await . len( ) , 3 ) ;
231+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
232+ crates/rate_limited1/rate_limited1-1.0.0.crate
233+ crates/rate_limited1/rate_limited1-1.0.1.crate
234+ index/ra/te/rate_limited1
235+ "### ) ;
206236
207237 // Uploading the second update to the crate is rate limited
208238 let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.2" ) ;
@@ -214,7 +244,11 @@ async fn publish_existing_crate_rate_limited() {
214244 // Check that version 1.0.2 was not published
215245 let json = anon. show_crate ( "rate_limited1" ) . await ;
216246 assert_eq ! ( json. krate. max_version, "1.0.1" ) ;
217- assert_eq ! ( app. stored_files( ) . await . len( ) , 3 ) ;
247+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
248+ crates/rate_limited1/rate_limited1-1.0.0.crate
249+ crates/rate_limited1/rate_limited1-1.0.1.crate
250+ index/ra/te/rate_limited1
251+ "### ) ;
218252
219253 // Wait for the limit to be up
220254 thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
@@ -224,7 +258,12 @@ async fn publish_existing_crate_rate_limited() {
224258
225259 let json = anon. show_crate ( "rate_limited1" ) . await ;
226260 assert_eq ! ( json. krate. max_version, "1.0.2" ) ;
227- assert_eq ! ( app. stored_files( ) . await . len( ) , 4 ) ;
261+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
262+ crates/rate_limited1/rate_limited1-1.0.0.crate
263+ crates/rate_limited1/rate_limited1-1.0.1.crate
264+ crates/rate_limited1/rate_limited1-1.0.2.crate
265+ index/ra/te/rate_limited1
266+ "### ) ;
228267}
229268
230269#[ tokio:: test( flavor = "multi_thread" ) ]
0 commit comments