summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSebastian Holmin <sebastian.holmin@mullvad.net>2024-07-22 16:41:41 +0200
committerMarkus Pettersson <markus.pettersson@mullvad.net>2024-08-09 09:43:58 +0200
commit7cff069918f4c412f11f45e098fdf2e22c3ea71b (patch)
treef33d458ee25f575bc993fdb135d76bb4a70d6c5e
parentb50501b9c2240c09628bf7e63d6ff398faf51f3b (diff)
downloadmullvadvpn-7cff069918f4c412f11f45e098fdf2e22c3ea71b.tar.xz
mullvadvpn-7cff069918f4c412f11f45e098fdf2e22c3ea71b.zip
Fix regex on release versions
-rw-r--r--test/test-manager/src/package.rs46
1 files changed, 37 insertions, 9 deletions
diff --git a/test/test-manager/src/package.rs b/test/test-manager/src/package.rs
index c1f9d0232b..4d8741f466 100644
--- a/test/test-manager/src/package.rs
+++ b/test/test-manager/src/package.rs
@@ -5,9 +5,6 @@ use once_cell::sync::Lazy;
use regex::Regex;
use std::path::{Path, PathBuf};
-static VERSION_REGEX: Lazy<Regex> =
- Lazy::new(|| Regex::new(r"\d{4}\.\d+(-beta\d+)?(-dev)?-([0-9a-z])+").unwrap());
-
#[derive(Debug, Clone)]
pub struct Manifest {
pub app_package_path: PathBuf,
@@ -44,12 +41,7 @@ pub fn get_app_manifest(
.expect("Path to app package should have parent")
.into(),
);
- let capture = VERSION_REGEX
- .captures(app_package_path.to_str().unwrap())
- .with_context(|| format!("Cannot parse version: {}", app_package_path.display()))?
- .get(0)
- .map(|c| c.as_str())
- .expect("Could not parse version from package name: {app_package}");
+ let capture = get_version_from_path(&app_package_path)?;
let ui_e2e_tests_path =
find_app(capture, true, package_type, Some(&ui_e2e_package_folder)).ok();
@@ -62,6 +54,18 @@ pub fn get_app_manifest(
})
}
+fn get_version_from_path(app_package_path: &Path) -> Result<&str, anyhow::Error> {
+ static VERSION_REGEX: Lazy<Regex> =
+ Lazy::new(|| Regex::new(r"\d{4}\.\d+((-beta\d+)?(-dev)?-([0-9a-z])+)?").unwrap());
+
+ VERSION_REGEX
+ .captures(app_package_path.to_str().unwrap())
+ .with_context(|| format!("Cannot parse version: {}", app_package_path.display()))?
+ .get(0)
+ .map(|c| c.as_str())
+ .context("Could not parse version from package name: {app_package}")
+}
+
fn find_app(
app: &str,
e2e_bin: bool,
@@ -138,3 +142,27 @@ fn get_os_name(package_type: (OsType, Option<PackageType>, Option<Architecture>)
OsType::Linux => "linux",
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_version_regex() {
+ let path = Path::new("../some/path/MullvadVPN-2024.4-beta1-dev-f7df8e_amd64.deb");
+ let capture = get_version_from_path(path).unwrap();
+ assert_eq!(capture, "2024.4-beta1-dev-f7df8e");
+
+ let path = Path::new("../some/path/MullvadVPN-2024.4-beta1-f7df8e_amd64.deb");
+ let capture = get_version_from_path(path).unwrap();
+ assert_eq!(capture, "2024.4-beta1-f7df8e");
+
+ let path = Path::new("../some/path/MullvadVPN-2024.4-dev-f7df8e_amd64.deb");
+ let capture = get_version_from_path(path).unwrap();
+ assert_eq!(capture, "2024.4-dev-f7df8e");
+
+ let path = Path::new("../some/path/MullvadVPN-2024.3_amd64.deb");
+ let capture = get_version_from_path(path).unwrap();
+ assert_eq!(capture, "2024.3");
+ }
+}