feat: repository architecture for files crate w. added tests (#498)
BIN
crates/core/files/tests/assets/anim-icos.apng
Normal file
|
After Width: | Height: | Size: 968 KiB |
BIN
crates/core/files/tests/assets/anim-icos.gif
Normal file
|
After Width: | Height: | Size: 375 KiB |
BIN
crates/core/files/tests/assets/anim-icos.jxl
Normal file
BIN
crates/core/files/tests/assets/anim-icos.webp
Normal file
|
After Width: | Height: | Size: 382 KiB |
BIN
crates/core/files/tests/assets/corrupted.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
crates/core/files/tests/assets/dice.jxl
Normal file
BIN
crates/core/files/tests/assets/dice.webp
Normal file
|
After Width: | Height: | Size: 64 KiB |
BIN
crates/core/files/tests/assets/test.jpeg
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
crates/core/files/tests/assets/test.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
31
crates/core/files/tests/integration_test.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use std::io::Cursor;
|
||||
|
||||
use revolt_files::{EncryptionKey, FileStorageRepository, MediaImpl, MediaRepository, S3Storage};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_image_roundtrip_png() {
|
||||
let media = MediaImpl::from_config().await;
|
||||
let encryption = EncryptionKey::from_config().await;
|
||||
let s3 = S3Storage::from_config(encryption).await;
|
||||
|
||||
let buf = include_bytes!("./assets/test.png");
|
||||
let bucket_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
s3.create_bucket(&bucket_id).await.unwrap();
|
||||
|
||||
let mut reader = Cursor::new(buf);
|
||||
media.decode_image(&mut reader, "image/png").unwrap();
|
||||
|
||||
let iv = s3
|
||||
.encrypt_and_upload_file(&bucket_id, "/my-file", buf)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let buf = s3
|
||||
.fetch_and_decrypt_file(&bucket_id, "/my-file", &iv)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut reader = Cursor::new(buf);
|
||||
media.decode_image(&mut reader, "image/png").unwrap();
|
||||
}
|
||||
42
crates/core/files/tests/s3_test.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use revolt_files::{EncryptionKey, FileStorageRepository, S3Storage};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_upload_and_download() {
|
||||
let encryption = EncryptionKey::from_config().await;
|
||||
let s3 = S3Storage::from_config(encryption).await;
|
||||
|
||||
let buf = [67];
|
||||
let bucket_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
s3.create_bucket(&bucket_id).await.unwrap();
|
||||
|
||||
let iv = s3
|
||||
.encrypt_and_upload_file(&bucket_id, "/my-file", &buf)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let buf = s3
|
||||
.fetch_and_decrypt_file(&bucket_id, "/my-file", &iv)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(buf.len(), 1);
|
||||
assert_eq!(buf[0], 67);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_upload_and_delete() {
|
||||
let encryption = EncryptionKey::from_config().await;
|
||||
let s3 = S3Storage::from_config(encryption).await;
|
||||
|
||||
let buf = [67];
|
||||
let bucket_id = uuid::Uuid::new_v4().to_string();
|
||||
|
||||
s3.create_bucket(&bucket_id).await.unwrap();
|
||||
|
||||
s3.encrypt_and_upload_file(&bucket_id, "/my-file", &buf)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
s3.delete_file(&bucket_id, "/my-file").await.unwrap();
|
||||
}
|
||||