diff --git a/src/ops/work_tree.rs b/src/ops/work_tree.rs index f7d1cab..c9d9b1b 100644 --- a/src/ops/work_tree.rs +++ b/src/ops/work_tree.rs @@ -154,7 +154,6 @@ where let result = (*self.function)(&mut self.context, response); let completed = self.results.send(result).is_err(); - self.completed = completed; } } diff --git a/src/ops/workspace.rs b/src/ops/workspace.rs index 7c6bb48..1ce1fb9 100644 --- a/src/ops/workspace.rs +++ b/src/ops/workspace.rs @@ -147,6 +147,7 @@ where "Licensa is already initialized in the current directory", )); } + Ok(()) } pub fn throw_no_workspace_config_exists

(workspace_root: P) -> Result<()> @@ -266,29 +267,19 @@ mod tests { #[test] fn test_write_config_file_successful() { - // Create a temporary directory for testing let temp_dir = tempdir().expect("Failed to create temporary directory"); - - // Define the target directory let target_dir = temp_dir.path(); - - // Define the output file path let config_file_path = target_dir.join(DEFAULT_CONFIG_FILENAME); - // Create a sample configuration let sample_config = ExampleWorkspace { prop1: "hello world".to_string(), prop2: 1234, }; - // Test writing the config file let write_result = save_workspace_config(target_dir, &sample_config); assert!(write_result.is_ok()); - - // Verify that the config file exists assert!(config_file_path.exists()); - // Verify the content of the config file let mut file = File::open(&config_file_path).expect("Failed to open config file"); let mut file_content = String::new(); file.read_to_string(&mut file_content) @@ -304,18 +295,12 @@ mod tests { #[test] fn test_write_config_file_existing_file() { - // Create a temporary directory for testing let temp_dir = tempdir().expect("Failed to create temporary directory"); - - // Define the target directory let target_dir = temp_dir.path(); - - // Create an existing config file in the temporary directory let existing_config_filename = POSSIBLE_CONFIG_FILENAMES[0]; let existing_config_path = target_dir.join(existing_config_filename); File::create(&existing_config_path).expect("Failed to create existing config file"); - // Create a sample configuration let sample_config = ExampleWorkspace { prop1: "hello world".to_string(), prop2: 1234, @@ -332,18 +317,12 @@ mod tests { #[test] fn test_find_config_file_single_file_exists() { - // Create a temporary directory for testing let temp_dir = tempdir().expect("Failed to create temporary directory"); - - // Define the target directory let target_dir = temp_dir.path(); - - // Create a sample config file in the temporary directory let sample_config_filename = POSSIBLE_CONFIG_FILENAMES[0]; let sample_config_path = target_dir.join(sample_config_filename); File::create(&sample_config_path).expect("Failed to create sample config file"); - // Test finding the config file let result: Result = resolve_workspace_config(target_dir); assert!(result.is_err()); diff --git a/src/template/cache.rs b/src/template/cache.rs index a206939..c390041 100644 --- a/src/template/cache.rs +++ b/src/template/cache.rs @@ -37,9 +37,7 @@ where /// * `item` - An item implementing the `Cachable` trait. pub fn set(&mut self, item: T) { let mut cache = self.inner.lock().unwrap(); - let cache_id = item.cache_id(); - cache.entry(cache_id).or_insert_with(|| Arc::new(item)); } @@ -50,9 +48,7 @@ where /// * `item` - An item implementing the `Cachable` trait. pub fn add(&self, item: T) { let mut cache = self.inner.lock().unwrap(); - let cache_id = item.cache_id(); - cache.entry(cache_id).or_insert_with(|| Arc::new(item)); } @@ -158,6 +154,7 @@ mod tests { pub template: String, pub extension: String, } + impl Cachable for TemplateItem { fn cache_id(&self) -> String { self.extension.clone() diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 1e68e3c..105722b 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -85,18 +85,10 @@ where /// /// Returns an error if there are issues creating or writing to the file. pub fn write_json>(file_path: P, json_data: &serde_json::Value) -> Result<()> { - // Create or open the file for writing let mut file = File::create(&file_path)?; - - // Serialize the JSON data to a pretty-printed string let json_string = serde_json::to_string_pretty(json_data)?; - - // Write the pretty-printed JSON string to the file file.write_all(json_string.as_bytes())?; - - // Flush the buffer to ensure the data is written to the file file.flush()?; - Ok(()) } diff --git a/src/workspace/ops.rs b/src/workspace/ops.rs index 7dd16ed..abb5430 100644 --- a/src/workspace/ops.rs +++ b/src/workspace/ops.rs @@ -124,6 +124,7 @@ where { let workspace_root = workspace_root.as_ref(); ensure_dir(workspace_root)?; + if let Some(path) = resolve_config_path(workspace_root, file_name) { let content = fs::read_to_string(path).with_context(|| "failed to read .licensarc config file")?; @@ -193,18 +194,20 @@ where { let workspace_root = workspace_root.as_ref(); ensure_dir(workspace_root)?; + let config = serde_json::to_value(config.borrow())?; - // Ensure config is an object if !config.is_object() { let err = anyhow!(WorkspaceError::InvalidConfigDataType) .context("failed to save workspace config file"); return Err(err.into()); } + let config = remove_null_fields(config); let config = serde_json::to_string_pretty(&config) .with_context(|| "failed to serialize .licensarc config file")?; let out_path = workspace_root.join(file_name.as_ref()); fs::write(out_path, config).with_context(|| "failed to save .licensarc config file")?; + Ok(()) } diff --git a/src/workspace/walker.rs b/src/workspace/walker.rs index 0159b2a..f8b7faa 100644 --- a/src/workspace/walker.rs +++ b/src/workspace/walker.rs @@ -400,6 +400,7 @@ mod tests { // Act let rx = walker.run_task(); + // Ensure config is an object // Assert // Add assertions for receiving results from the workspace walk }