Skip to content

Commit ef295b3

Browse files
pietroalbiniJoshua Nelson
authored andcommitted
storage: move test for batched uploads to the backend tests
1 parent a4ce63e commit ef295b3

File tree

1 file changed

+26
-58
lines changed

1 file changed

+26
-58
lines changed

src/storage/mod.rs

Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -245,66 +245,8 @@ fn detect_mime(file_path: &Path) -> Result<&'static str, Error> {
245245
#[cfg(test)]
246246
mod test {
247247
use super::*;
248-
use crate::test::wrapper;
249248
use std::env;
250249

251-
pub(crate) fn assert_blob_eq(blob: &Blob, actual: &Blob) {
252-
assert_eq!(blob.path, actual.path);
253-
assert_eq!(blob.content, actual.content);
254-
assert_eq!(blob.mime, actual.mime);
255-
// NOTE: this does _not_ compare the upload time since min.io doesn't allow this to be configured
256-
}
257-
258-
pub(crate) fn test_roundtrip(blobs: &[Blob]) {
259-
let dir = tempfile::Builder::new()
260-
.prefix("docs.rs-upload-test")
261-
.tempdir()
262-
.unwrap();
263-
for blob in blobs {
264-
let path = dir.path().join(&blob.path);
265-
if let Some(parent) = path.parent() {
266-
fs::create_dir_all(parent).unwrap();
267-
}
268-
fs::write(path, &blob.content).expect("failed to write to file");
269-
}
270-
wrapper(|env| {
271-
let db = env.db();
272-
let backend = Storage {
273-
backend: StorageBackend::Database(DatabaseBackend::new(db.pool())),
274-
};
275-
let (stored_files, _algs) = backend.store_all("", dir.path()).unwrap();
276-
assert_eq!(stored_files.len(), blobs.len());
277-
for blob in blobs {
278-
let name = Path::new(&blob.path);
279-
assert!(stored_files.contains_key(name));
280-
281-
let actual = backend.get(&blob.path, std::usize::MAX).unwrap();
282-
assert_blob_eq(blob, &actual);
283-
}
284-
285-
Ok(())
286-
});
287-
}
288-
289-
#[test]
290-
fn test_batched_uploads() {
291-
let uploads: Vec<_> = (0..=MAX_CONCURRENT_UPLOADS + 1)
292-
.map(|i| {
293-
let alg = CompressionAlgorithm::default();
294-
let content = compress("fn main() {}".as_bytes(), alg).unwrap();
295-
Blob {
296-
mime: "text/rust".into(),
297-
content,
298-
path: format!("{}.rs", i),
299-
date_updated: Utc::now(),
300-
compression: Some(alg),
301-
}
302-
})
303-
.collect();
304-
305-
test_roundtrip(&uploads);
306-
}
307-
308250
#[test]
309251
fn test_get_file_list() {
310252
crate::test::init_logger();
@@ -486,6 +428,31 @@ mod backend_tests {
486428
Ok(())
487429
}
488430

431+
fn test_batched_uploads(storage: &Storage) -> Result<(), Error> {
432+
let now = Utc::now();
433+
let uploads: Vec<_> = (0..=MAX_CONCURRENT_UPLOADS + 1)
434+
.map(|i| {
435+
let content = format!("const IDX: usize = {};", i).as_bytes().to_vec();
436+
Blob {
437+
mime: "text/rust".into(),
438+
content,
439+
path: format!("{}.rs", i),
440+
date_updated: now.clone(),
441+
compression: None,
442+
}
443+
})
444+
.collect();
445+
446+
storage.store_blobs(uploads.clone())?;
447+
448+
for blob in &uploads {
449+
let stored = storage.get(&blob.path, std::usize::MAX)?;
450+
assert_eq!(&stored.content, &blob.content);
451+
}
452+
453+
Ok(())
454+
}
455+
489456
// Remember to add the test name to the macro below when adding a new one.
490457

491458
macro_rules! backend_tests {
@@ -523,6 +490,7 @@ mod backend_tests {
523490
}
524491

525492
tests {
493+
test_batched_uploads,
526494
test_get_object,
527495
test_get_too_big,
528496
test_store_blobs,

0 commit comments

Comments
 (0)