docbox-storage 0.8.2

Docbox storage layer abstraction
Documentation
use docbox_storage::UploadFileOptions;

use crate::common::minio::{test_minio_container, test_storage_factory};

mod common;

/// Tests getting a file's content succeeds and matches the uploaded content
#[tokio::test]
async fn test_get_file_minio() {
    let container = test_minio_container().await;
    let storage_factory = test_storage_factory(&container).await;
    let storage = storage_factory.create_test_layer();

    storage.create_bucket().await.unwrap();
    storage
        .upload_file(
            "test.txt",
            "test".into(),
            UploadFileOptions {
                content_type: "text/plain".to_string(),
                ..Default::default()
            },
        )
        .await
        .unwrap();

    let contents = storage
        .get_file("test.txt")
        .await
        .unwrap()
        .collect_bytes()
        .await
        .unwrap();

    assert_eq!(contents.as_ref(), b"test");
}

/// Tests getting the contents of an unknown file fails
#[tokio::test]
async fn test_get_unknown_file_minio() {
    let container = test_minio_container().await;
    let storage_factory = test_storage_factory(&container).await;
    let storage = storage_factory.create_test_layer();

    storage.create_bucket().await.unwrap();
    storage.get_file("test.txt").await.unwrap_err();
}