@@ -5,6 +5,7 @@ use crates_io::rate_limiter::LimitedAction;
5
5
use crates_io:: schema:: { publish_limit_buckets, publish_rate_overrides} ;
6
6
use diesel:: { ExpressionMethods , RunQueryDsl } ;
7
7
use http:: StatusCode ;
8
+ use insta:: assert_snapshot;
8
9
use std:: thread;
9
10
use std:: time:: Duration ;
10
11
@@ -35,7 +36,7 @@ async fn publish_new_crate_ratelimit_hit() {
35
36
. await
36
37
. assert_rate_limited ( LimitedAction :: PublishNew ) ;
37
38
38
- assert_eq ! ( app. stored_files( ) . await . len ( ) , 0 ) ;
39
+ assert_snapshot ! ( app. stored_files( ) . await . join ( " \n " ) , @ "" ) ;
39
40
40
41
let response = anon. get :: < ( ) > ( "/api/v1/crates/rate_limited" ) . await ;
41
42
assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
@@ -65,7 +66,10 @@ async fn publish_new_crate_ratelimit_expires() {
65
66
let crate_to_publish = PublishBuilder :: new ( "rate_limited" , "1.0.0" ) ;
66
67
token. publish_crate ( crate_to_publish) . await . good ( ) ;
67
68
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
+ "### ) ;
69
73
70
74
let json = anon. show_crate ( "rate_limited" ) . await ;
71
75
assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
@@ -98,15 +102,22 @@ async fn publish_new_crate_override_loosens_ratelimit() {
98
102
let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.0" ) ;
99
103
token. publish_crate ( crate_to_publish) . await . good ( ) ;
100
104
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
+ "### ) ;
102
109
103
110
let json = anon. show_crate ( "rate_limited1" ) . await ;
104
111
assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
105
112
106
113
let crate_to_publish = PublishBuilder :: new ( "rate_limited2" , "1.0.0" ) ;
107
114
token. publish_crate ( crate_to_publish) . await . good ( ) ;
108
115
109
- assert_eq ! ( app. stored_files( ) . await . len( ) , 4 ) ;
116
+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
117
+ crates/foo_new/foo_new-1.0.0.crate
118
+ index/fo/o_/foo_new
119
+ rss/updates.xml
120
+ "### ) ;
110
121
111
122
let json = anon. show_crate ( "rate_limited2" ) . await ;
112
123
assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
@@ -117,7 +128,11 @@ async fn publish_new_crate_override_loosens_ratelimit() {
117
128
. await
118
129
. assert_rate_limited ( LimitedAction :: PublishNew ) ;
119
130
120
- assert_eq ! ( app. stored_files( ) . await . len( ) , 4 ) ;
131
+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
132
+ crates/foo_new/foo_new-1.0.0.crate
133
+ index/fo/o_/foo_new
134
+ rss/updates.xml
135
+ "### ) ;
121
136
122
137
let response = anon. get :: < ( ) > ( "/api/v1/crates/rate_limited3" ) . await ;
123
138
assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
@@ -151,7 +166,10 @@ async fn publish_new_crate_expired_override_ignored() {
151
166
let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.0" ) ;
152
167
token. publish_crate ( crate_to_publish) . await . good ( ) ;
153
168
154
- assert_eq ! ( app. stored_files( ) . await . len( ) , 2 ) ;
169
+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
170
+ crates/rate_limited1/rate_limited1-1.0.0.crate
171
+ index/ra/te/rate_limited1
172
+ "### ) ;
155
173
156
174
let json = anon. show_crate ( "rate_limited1" ) . await ;
157
175
assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
@@ -162,7 +180,11 @@ async fn publish_new_crate_expired_override_ignored() {
162
180
. await
163
181
. assert_rate_limited ( LimitedAction :: PublishNew ) ;
164
182
165
- assert_eq ! ( app. stored_files( ) . await . len( ) , 2 ) ;
183
+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
184
+ crates/foo_new/foo_new-1.0.0.crate
185
+ index/fo/o_/foo_new
186
+ rss/updates.xml
187
+ "### ) ;
166
188
167
189
let response = anon. get :: < ( ) > ( "/api/v1/crates/rate_limited2" ) . await ;
168
190
assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
@@ -194,15 +216,22 @@ async fn publish_existing_crate_rate_limited() {
194
216
195
217
let json = anon. show_crate ( "rate_limited1" ) . await ;
196
218
assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
197
- assert_eq ! ( app. stored_files( ) . await . len( ) , 2 ) ;
219
+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
220
+ crates/rate_limited1/rate_limited1-1.0.0.crate
221
+ index/ra/te/rate_limited1
222
+ "### ) ;
198
223
199
224
// Uploading the first update to the crate works
200
225
let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.1" ) ;
201
226
token. publish_crate ( crate_to_publish) . await . good ( ) ;
202
227
203
228
let json = anon. show_crate ( "rate_limited1" ) . await ;
204
229
assert_eq ! ( json. krate. max_version, "1.0.1" ) ;
205
- assert_eq ! ( app. stored_files( ) . await . len( ) , 3 ) ;
230
+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
231
+ crates/foo_new/foo_new-1.0.0.crate
232
+ index/fo/o_/foo_new
233
+ rss/updates.xml
234
+ "### ) ;
206
235
207
236
// Uploading the second update to the crate is rate limited
208
237
let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.2" ) ;
@@ -214,7 +243,11 @@ async fn publish_existing_crate_rate_limited() {
214
243
// Check that version 1.0.2 was not published
215
244
let json = anon. show_crate ( "rate_limited1" ) . await ;
216
245
assert_eq ! ( json. krate. max_version, "1.0.1" ) ;
217
- assert_eq ! ( app. stored_files( ) . await . len( ) , 3 ) ;
246
+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
247
+ crates/foo_new/foo_new-1.0.0.crate
248
+ index/fo/o_/foo_new
249
+ rss/updates.xml
250
+ "### ) ;
218
251
219
252
// Wait for the limit to be up
220
253
thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
@@ -224,7 +257,11 @@ async fn publish_existing_crate_rate_limited() {
224
257
225
258
let json = anon. show_crate ( "rate_limited1" ) . await ;
226
259
assert_eq ! ( json. krate. max_version, "1.0.2" ) ;
227
- assert_eq ! ( app. stored_files( ) . await . len( ) , 4 ) ;
260
+ assert_snapshot ! ( app. stored_files( ) . await . join( "\n " ) , @r###"
261
+ crates/foo_new/foo_new-1.0.0.crate
262
+ index/fo/o_/foo_new
263
+ rss/updates.xml
264
+ "### ) ;
228
265
}
229
266
230
267
#[ tokio:: test( flavor = "multi_thread" ) ]
0 commit comments