used by main for tests
(path: &str)
| 28 | // will assert an error if used version installed is not the same as written in file |
| 29 | #[allow(dead_code)] // used by main for tests |
| 30 | pub fn check_versions_from(path: &str) -> Result<(), EngineInitError> { |
| 31 | fn read_lines<P: AsRef<Path>>(filename: P) -> io::Result<io::Lines<BufReader<File>>> { |
| 32 | let file = File::open(filename)?; |
| 33 | Ok(BufReader::new(file).lines()) |
| 34 | } |
| 35 | |
| 36 | // please append this vector if you want to test more binaries |
| 37 | let bin_to_check = ["terraform"]; |
| 38 | |
| 39 | let lines: Vec<String> = read_lines(path) |
| 40 | .map_err(|err| { |
| 41 | error!("{}", err); |
| 42 | EngineInitError::Regular(BinVersion) |
| 43 | })? |
| 44 | .collect::<Result<Vec<String>, _>>() |
| 45 | .map_err(|err| { |
| 46 | error!("{}", err); |
| 47 | EngineInitError::Regular(BinVersion) |
| 48 | })?; |
| 49 | |
| 50 | // read line by line the version file |
| 51 | for line in lines.iter() { |
| 52 | // put in lowercase and split the BINARY_VERSION to BINARY |
| 53 | let lowercase = line.to_lowercase(); |
| 54 | //TODO FIX Do not parse correctly binary names in bin_versions. It should split at = instead of _ |
| 55 | //Modify bin_version format and edit the parsing |
| 56 | let binary_name = lowercase.split('_').next().unwrap_or(""); |
| 57 | |
| 58 | // check if the binary need to be tested |
| 59 | if bin_to_check.contains(&binary_name) { |
| 60 | let result_cmd = cmd::command::run_version_command_for(binary_name); |
| 61 | let version = lowercase.split('=').next_back().unwrap_or("").replace('"', ""); |
| 62 | |
| 63 | if !result_cmd.contains(&version) { |
| 64 | return Err(EngineInitError::Regular(BinVersion)); |
| 65 | } |
| 66 | |
| 67 | info!("{} is on right version {}", binary_name.to_string(), version); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | Ok(()) |
| 72 | } |
| 73 | |
| 74 | fn parse_candidate_deployed_engine_version(candidate: &str) -> Option<DeployedEngineVersion> { |
| 75 | let candidate = candidate.trim(); |
no test coverage detected