diff --git a/services/commtest/tests/blob_test.rs b/services/commtest/tests/blob_test.rs --- a/services/commtest/tests/blob_test.rs +++ b/services/commtest/tests/blob_test.rs @@ -1,10 +1,63 @@ +#[path = "./blob/blob_utils.rs"] +mod blob_utils; +#[path = "./blob/get.rs"] +mod get; +#[path = "./blob/put.rs"] +mod put; +#[path = "./blob/remove.rs"] +mod remove; #[path = "./lib/tools.rs"] mod tools; -use tools::Error; +use bytesize::ByteSize; + +use blob_utils::{BlobData, BlobServiceClient}; +use tools::{get_grpc_chunk_size_limit as chunk_limit, Error}; #[tokio::test] async fn blob_test() -> Result<(), Error> { - assert!(false, "not implemented"); + let mut client = BlobServiceClient::connect("http://localhost:50053").await?; + + let blob_data = vec![ + BlobData { + holder: "test_holder001".to_string(), + hash: "test_hash001".to_string(), + chunks_sizes: vec![ByteSize::b(100).as_u64() as usize, ByteSize::b(100).as_u64() as usize, ByteSize::b(100).as_u64() as usize], + }, + BlobData { + holder: "test_holder002".to_string(), + hash: "test_hash002".to_string(), + chunks_sizes: vec![chunk_limit(), chunk_limit(), ByteSize::b(10).as_u64() as usize], + }, + BlobData { + holder: "test_holder003".to_string(), + hash: "test_hash003".to_string(), + chunks_sizes: vec![chunk_limit(), ByteSize::b(100).as_u64() as usize, chunk_limit()], + }, + ]; + + for item in &blob_data { + let data_exists: bool = put::run(&mut client, &item).await?; + assert!(!data_exists, "test data should not exist"); + } + + for (i, blob_item) in blob_data.iter().enumerate() { + let received_sizes = get::run(&mut client, &blob_item).await?; + let expected_data_size = blob_item.chunks_sizes.iter().sum::(); + let received_data_size = received_sizes.iter().sum::(); + assert_eq!( + expected_data_size, received_data_size, + "invalid size of data for index {}, expected {}, got {}", + i, + expected_data_size, + received_data_size + ); + } + + for item in &blob_data { + remove::run(&mut client, &item).await?; + assert!(get::run(&mut client, &item).await.is_err(), "item should no longer be available"); + } + Ok(()) }