From 748d9091ec458b04278a8c9701fbead337a5d83d Mon Sep 17 00:00:00 2001 From: initard Date: Thu, 28 Apr 2022 11:37:33 +0100 Subject: fixing tests to work with CumulocityConverter changes #1027 - added a from_logs_path method for CumulocityConverter, allowing the possibility to specify tempDir for logs paths Signed-off-by: initard --- crates/core/tedge_mapper/src/c8y/mapper.rs | 5 ++++- crates/core/tedge_mapper/src/c8y/tests.rs | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) (limited to 'crates/core/tedge_mapper/src') diff --git a/crates/core/tedge_mapper/src/c8y/mapper.rs b/crates/core/tedge_mapper/src/c8y/mapper.rs index b5f9c275..6b5a8b3a 100644 --- a/crates/core/tedge_mapper/src/c8y/mapper.rs +++ b/crates/core/tedge_mapper/src/c8y/mapper.rs @@ -123,6 +123,7 @@ mod tests { use mqtt_tests::{assert_received_all_expected, test_mqtt_broker}; use serde_json::json; use std::time::Duration; + use tempfile::TempDir; use test_case::test_case; const TEST_TIMEOUT_SECS: Duration = Duration::from_secs(5); @@ -180,13 +181,15 @@ mod tests { let size_threshold = SizeThreshold(MQTT_MESSAGE_SIZE_THRESHOLD); let operations = Operations::default(); + let tmp_dir = TempDir::new().unwrap(); let converter = Box::new( - CumulocityConverter::new( + CumulocityConverter::from_logs_path( size_threshold, DEVICE_NAME.into(), DEVICE_TYPE.into(), operations, proxy, + tmp_dir.into_path(), ) .unwrap(), ); diff --git a/crates/core/tedge_mapper/src/c8y/tests.rs b/crates/core/tedge_mapper/src/c8y/tests.rs index 03477298..2e8ccc0e 100644 --- a/crates/core/tedge_mapper/src/c8y/tests.rs +++ b/crates/core/tedge_mapper/src/c8y/tests.rs @@ -19,6 +19,7 @@ use mqtt_tests::test_mqtt_server::MqttProcessHandler; use serde_json::json; use serial_test::serial; use std::{path::Path, time::Duration}; +use tempfile::TempDir; use test_case::test_case; use tokio::task::JoinHandle; @@ -939,12 +940,25 @@ fn create_c8y_converter() -> CumulocityConverter { let operations = Operations::default(); let http_proxy = FakeC8YHttpProxy {}; - CumulocityConverter::new( + let tmp_dir = TempDir::new().unwrap(); + std::fs::create_dir_all(&format!( + "{}/tedge/agent/", + &tmp_dir.path().to_str().unwrap() + )) + .unwrap(); + std::fs::File::create(&format!( + "{}/tedge/agent/software-list-2011-11-11T11:11:11Z.log", + &tmp_dir.path().to_str().unwrap() + )) + .unwrap(); + + CumulocityConverter::from_logs_path( size_threshold, device_name, device_type, operations, http_proxy, + tmp_dir.into_path(), ) .unwrap() } -- cgit v1.2.3