diff --git a/services/commtest/tests/backup/add_attachments.rs b/services/commtest/tests/backup/add_attachments.rs new file mode 100644 index 000000000..5570e9312 --- /dev/null +++ b/services/commtest/tests/backup/add_attachments.rs @@ -0,0 +1,53 @@ +#[path = "./backup_utils.rs"] +mod backup_utils; +#[path = "../lib/tools.rs"] +mod tools; + +use crate::backup_utils::{proto::AddAttachmentsRequest, BackupServiceClient}; + +use tonic::Request; + +use crate::backup_utils::BackupData; +use crate::tools::{Error, ATTACHMENT_DELIMITER}; + +// log_index = None means that we add attachments to the backup +// log_index = Some(x) means that we add attachments to a specific log +pub async fn run( + client: &mut BackupServiceClient, + backup_data: &BackupData, + log_index: Option, +) -> Result<(), Error> { + let cloned_user_id = backup_data.user_id.clone(); + let cloned_backup_id = backup_data.backup_item.id.clone(); + let log_id: String = match log_index { + Some(index) => { + let log_id = backup_data.log_items[index].id.clone(); + println!("add attachments for log {}/{}", index, log_id); + log_id + }, + None => { + println!("add attachments for backup"); + String::new() + }, + }; + + let holders: String = match log_index { + Some(log_index) => backup_data.log_items[log_index] + .attachments_holders + .join(ATTACHMENT_DELIMITER), + None => backup_data + .backup_item + .attachments_holders + .join(ATTACHMENT_DELIMITER), + }; + + client + .add_attachments(Request::new(AddAttachmentsRequest { + user_id: cloned_user_id, + backup_id: cloned_backup_id, + log_id, + holders, + })) + .await?; + Ok(()) +} diff --git a/services/commtest/tests/lib/tools.rs b/services/commtest/tests/lib/tools.rs index fb382fdab..6df15de8d 100644 --- a/services/commtest/tests/lib/tools.rs +++ b/services/commtest/tests/lib/tools.rs @@ -1,22 +1,22 @@ use bytesize::ByteSize; #[allow(dead_code)] pub fn generate_nbytes(number_of_bytes: usize, predefined_byte_value: Option) -> Vec { let byte_value = predefined_byte_value.unwrap_or(b'A'); return vec![byte_value; number_of_bytes]; } #[derive( Debug, derive_more::Display, derive_more::From, derive_more::Error, )] pub enum Error { #[display(...)] Proto(std::io::Error), #[display(...)] Tonic(tonic::transport::Error), #[display(...)] TonicStatus(tonic::Status), } #[allow(dead_code)] -pub const ATTACHMENT_DELIMITER: char = ';'; +pub const ATTACHMENT_DELIMITER: &str = ";";