@@ -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
@@ -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,23 @@ 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/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
+ "### ) ;
110
122
111
123
let json = anon. show_crate ( "rate_limited2" ) . await ;
112
124
assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
@@ -117,7 +129,12 @@ async fn publish_new_crate_override_loosens_ratelimit() {
117
129
. await
118
130
. assert_rate_limited ( LimitedAction :: PublishNew ) ;
119
131
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
+ "### ) ;
121
138
122
139
let response = anon. get :: < ( ) > ( "/api/v1/crates/rate_limited3" ) . await ;
123
140
assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
@@ -151,7 +168,10 @@ async fn publish_new_crate_expired_override_ignored() {
151
168
let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.0" ) ;
152
169
token. publish_crate ( crate_to_publish) . await . good ( ) ;
153
170
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
+ "### ) ;
155
175
156
176
let json = anon. show_crate ( "rate_limited1" ) . await ;
157
177
assert_eq ! ( json. krate. max_version, "1.0.0" ) ;
@@ -162,7 +182,10 @@ async fn publish_new_crate_expired_override_ignored() {
162
182
. await
163
183
. assert_rate_limited ( LimitedAction :: PublishNew ) ;
164
184
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
+ "### ) ;
166
189
167
190
let response = anon. get :: < ( ) > ( "/api/v1/crates/rate_limited2" ) . await ;
168
191
assert_eq ! ( response. status( ) , StatusCode :: NOT_FOUND ) ;
@@ -194,15 +217,22 @@ async fn publish_existing_crate_rate_limited() {
194
217
195
218
let json = anon. show_crate ( "rate_limited1" ) . await ;
196
219
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
+ "### ) ;
198
224
199
225
// Uploading the first update to the crate works
200
226
let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.1" ) ;
201
227
token. publish_crate ( crate_to_publish) . await . good ( ) ;
202
228
203
229
let json = anon. show_crate ( "rate_limited1" ) . await ;
204
230
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
+ "### ) ;
206
236
207
237
// Uploading the second update to the crate is rate limited
208
238
let crate_to_publish = PublishBuilder :: new ( "rate_limited1" , "1.0.2" ) ;
@@ -214,7 +244,11 @@ async fn publish_existing_crate_rate_limited() {
214
244
// Check that version 1.0.2 was not published
215
245
let json = anon. show_crate ( "rate_limited1" ) . await ;
216
246
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
+ "### ) ;
218
252
219
253
// Wait for the limit to be up
220
254
thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
@@ -224,7 +258,12 @@ async fn publish_existing_crate_rate_limited() {
224
258
225
259
let json = anon. show_crate ( "rate_limited1" ) . await ;
226
260
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
+ "### ) ;
228
267
}
229
268
230
269
#[ tokio:: test( flavor = "multi_thread" ) ]
0 commit comments