Skip to content

Commit

Permalink
Use Vec<String> instead Option<Vec<String>> in TestScriptManager (#…
Browse files Browse the repository at this point in the history
…37)

* fix: add aider to gitignore

* fix: testscript_manager use Vec<String>

* fix: clear unused parameter
  • Loading branch information
panglars authored Oct 21, 2024
1 parent 6fb7af8 commit c8bd91b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*report.json
*reports.json
*summary.md
.aider*
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ fn run_tests(distros: &[&str], packages: &[&str], skip_successful: bool, dir: &P
))
};

match test_runner.run_test(distro, package, Some(skipped_scripts), dir) {
match test_runner.run_test(distro, package, skipped_scripts, dir) {
Ok(_) => info!("Test passed for {}/{}", distro, package),
Err(e) => error!("Test failed for {}/{}: {}", distro, package, e), // error or warn?
}
Expand Down
2 changes: 1 addition & 1 deletion src/test_runner/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl TestRunner for LocalTestRunner {
&self,
distro: &str,
package: &str,
skip_scripts: Option<Vec<String>>,
skip_scripts: Vec<String>,
dir: &Path,
) -> Result<(), Box<dyn std::error::Error>> {
let script_manager = TestScriptManager::new(distro, package, skip_scripts, dir)?;
Expand Down
2 changes: 1 addition & 1 deletion src/test_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait TestRunner {
&self,
distro: &str,
package: &str,
skip_scripts: Option<Vec<String>>,
skip_scripts: Vec<String>,
dir: &Path,
) -> Result<(), Box<dyn std::error::Error>>;
}
2 changes: 1 addition & 1 deletion src/test_runner/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl TestRunner for RemoteTestRunner {
&self,
distro: &str,
package: &str,
skip_scripts: Option<Vec<String>>,
skip_scripts: Vec<String>,
dir: &Path,
) -> Result<(), Box<dyn std::error::Error>> {
// Create SSH session
Expand Down
24 changes: 10 additions & 14 deletions src/testscript_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ use std::path::Path;
///
/// This struct is responsible for discovering and storing paths to test scripts
/// located in a specific directory structure.
#[allow(dead_code)]
pub struct TestScriptManager {
test_scripts: Vec<String>,
metadata_script: Option<String>,
skipped_scripts: Vec<String>,
}

/// The name of the metadata script, if it exists.
Expand Down Expand Up @@ -51,13 +49,12 @@ impl TestScriptManager {
pub fn new(
distro: &str,
package: &str,
skip_scripts: Option<Vec<String>>,
skip_scripts: Vec<String>,
working_dir: &Path,
) -> Result<Self, Box<dyn std::error::Error>> {
let directory = working_dir.join(format!("{}/{}", distro, package));
let mut test_scripts = Vec::new();
let mut metadata_script = None;
let skipped_scripts = skip_scripts.unwrap_or_default();

for entry in std::fs::read_dir(directory)? {
let entry = entry?;
Expand All @@ -66,7 +63,7 @@ impl TestScriptManager {
let final_path = path.to_str().unwrap_or_default().to_string();
let file_name = path.file_name();

if skipped_scripts.contains(&file_name.unwrap().to_string_lossy().to_string()) {
if skip_scripts.contains(&file_name.unwrap().to_string_lossy().to_string()) {
log::debug!("skipped {}", file_name.unwrap().to_string_lossy());
continue;
}
Expand All @@ -78,22 +75,20 @@ impl TestScriptManager {
test_scripts.push(final_path);
}
}
}

if metadata_script.is_none() {
log::warn!(
"Missing metadata.sh for {}/{}, its metadata will not be recorded",
distro,
package
);
if metadata_script.is_none() {
log::warn!(
"Missing metadata.sh for {}/{}, its metadata will not be recorded",
distro,
package
);
}
}
Ok(TestScriptManager {
test_scripts,
metadata_script,
skipped_scripts,
})
}

/// Returns a slice containing the paths of all discovered test scripts.
///
/// # Returns
Expand All @@ -111,6 +106,7 @@ impl TestScriptManager {
/// println!("Test script: {}", script);
/// }
/// ```
/// Returns a slice containing the paths of all discovered test scripts.
pub fn get_test_scripts(&self) -> &[String] {
&self.test_scripts
}
Expand Down

0 comments on commit c8bd91b

Please sign in to comment.