Updates
All checks were successful
Build Project / test (push) Successful in 5m58s

This commit is contained in:
2025-01-19 15:43:04 +01:00
parent e19a11d5f3
commit e5339f7c6c
5 changed files with 47 additions and 26 deletions

View File

@@ -52,12 +52,13 @@ pub fn get_files(root_path: &PathBuf, hostname: &str) -> Result<Vec<OTAConfigura
let entries = fs::read_dir(root_path)?;
for entry in entries.flatten() {
info!("Reading entry: {entry:?}");
let path = entry.path();
if path.is_file() {
println!("File: {:?}", path);
info!("processing file: {:?}", path);
// Splits the filename at the underscores. This is safe to do as names get sanitized on upload and are only uploaded by the pipeline
let split_name: Vec<_> = path.file_name().ok_or(GetFilesError::Filename)?.to_str().ok_or(GetFilesError::Filename)?.split("_").collect();
let version = split_name[2].strip_suffix(".bin").ok_or(GetFilesError::Extension)?;
let version = split_name[2].strip_suffix(".bin").ok_or(GetFilesError::Extension)?.replace("-", ".");
let board_config = BoardConfig::from_str(split_name[1])?;
let board_type = BoardType::from_str(&product_name).unwrap();
let version_replaced = version.replace(".", "_");
@@ -85,8 +86,8 @@ mod tests {
let expected_2 = OTAConfiguration{ version: "4.5.6".to_string(), url: "example.com/firmware/waterlevel/INA226/4_5_6.bin".to_string(), board: Some(BoardType::Waterlevel), config: Some(BoardConfig::INA226) };
let loaded_configs = get_files(&PathBuf::from("./test/waterlevel"), "example.com").unwrap();
assert_eq!(loaded_configs[0], expected_1);
assert_eq!(loaded_configs[1], expected_2);
assert_eq!(loaded_configs[1], expected_1);
assert_eq!(loaded_configs[0], expected_2);
}
#[test]