From fed8e29a4440ccb832789e4edf31a6090cade6ad Mon Sep 17 00:00:00 2001 From: Krzysztof Piotrowski Date: Tue, 6 Feb 2024 11:18:04 +0000 Subject: [PATCH] Add test for handling special characters in module version Signed-off-by: Krzysztof Piotrowski --- crates/core/plugin_sm/src/plugin.rs | 2 +- crates/core/plugin_sm/tests/plugin.rs | 14 +++++++++++++ .../RobotFramework/tests/plugin_apt/build.sh | 8 ++++++-- .../install_overwrite_config_files.robot | 5 +++++ .../plugin_apt/nfpm-package-with-epoch.yaml | 19 ++++++++++++++++++ .../package-with-epoch_1.2.3_all.deb | Bin 0 -> 774 bytes 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 tests/RobotFramework/tests/plugin_apt/nfpm-package-with-epoch.yaml create mode 100644 tests/RobotFramework/tests/plugin_apt/package-with-epoch_1.2.3_all.deb diff --git a/crates/core/plugin_sm/src/plugin.rs b/crates/core/plugin_sm/src/plugin.rs index ed3e1fc989d..44a7af66fad 100644 --- a/crates/core/plugin_sm/src/plugin.rs +++ b/crates/core/plugin_sm/src/plugin.rs @@ -547,7 +547,7 @@ pub fn deserialize_module_info( Ok(software_list) } -fn sm_path(name: &str, version: &Option, target_dir_path: impl AsRef) -> PathBuf { +pub fn sm_path(name: &str, version: &Option, target_dir_path: impl AsRef) -> PathBuf { let mut filename = name.to_string(); if let Some(version) = version { filename.push('_'); diff --git a/crates/core/plugin_sm/tests/plugin.rs b/crates/core/plugin_sm/tests/plugin.rs index 2125437ec28..90a1c3e7753 100644 --- a/crates/core/plugin_sm/tests/plugin.rs +++ b/crates/core/plugin_sm/tests/plugin.rs @@ -2,9 +2,11 @@ mod tests { use plugin_sm::plugin::deserialize_module_info; + use plugin_sm::plugin::sm_path; use plugin_sm::plugin::ExternalPluginCommand; use serial_test::serial; use std::io::Write; + use std::path::Path; use std::path::PathBuf; use std::str::FromStr; use tedge_api::SoftwareError; @@ -147,6 +149,18 @@ mod tests { assert_eq!(res, Ok(())); } + #[test_case("abc", &Some("1:2.3.4567-8~1234".to_string()), "/tmp", PathBuf::from("/tmp/abc_1%3a2.3.4567-8~1234") ; "with special character")] + fn handle_special_characters_in_module_version( + name: &str, + version: &Option, + target_dir_path: impl AsRef, + expected_path: PathBuf, + ) { + let res = sm_path(name, version, target_dir_path); + + assert_eq!(res, expected_path); + } + fn get_dummy_plugin_path() -> PathBuf { // Return a path to a dummy plugin in target directory. let package_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); diff --git a/tests/RobotFramework/tests/plugin_apt/build.sh b/tests/RobotFramework/tests/plugin_apt/build.sh index 53e9fe57ac1..5a56b57477e 100755 --- a/tests/RobotFramework/tests/plugin_apt/build.sh +++ b/tests/RobotFramework/tests/plugin_apt/build.sh @@ -1,4 +1,8 @@ #!/usr/bin/env bash +set -e SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -nfpm package -f "$SCRIPT_DIR/nfpm-version1.yaml" --target "$SCRIPT_DIR/" --packager deb -nfpm package -f "$SCRIPT_DIR/nfpm-version2.yaml" --target "$SCRIPT_DIR/" --packager deb +pushd "$SCRIPT_DIR" 2>/dev/null ||: +nfpm package -f "nfpm-version1.yaml" --target "./" --packager deb +nfpm package -f "nfpm-version2.yaml" --target "./" --packager deb +nfpm package -f "nfpm-package-with-epoch.yaml" --target "./" --packager deb +popd 2>/dev/null ||: diff --git a/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot b/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot index ca01dbc1988..351ddd48bd6 100644 --- a/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot +++ b/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot @@ -45,6 +45,11 @@ Install packages overwrite config files ${output}= Execute Command cat /etc/sampledeb.cfg Should Contain ${output} conf 2.0 +Install package with Epoch in version #2666 + ${FILE_URL}= Cumulocity.Create Inventory Binary package-with-epoch package file=${CURDIR}/package-with-epoch_1.2.3_all.deb + ${OPERATION}= Install Software {"name": "package-with-epoch", "version": "2:1.2.3", "softwareType": "apt", "url": "${FILE_URL}"} + ${OPERATION}= Operation Should Be SUCCESSFUL ${OPERATION} timeout=60 + Device Should Have Installed Software {"name": "package-with-epoch", "version": "2:1.2.3", "softwareType": "apt"} *** Keywords *** Custom Setup diff --git a/tests/RobotFramework/tests/plugin_apt/nfpm-package-with-epoch.yaml b/tests/RobotFramework/tests/plugin_apt/nfpm-package-with-epoch.yaml new file mode 100644 index 00000000000..0ca70b44f6a --- /dev/null +++ b/tests/RobotFramework/tests/plugin_apt/nfpm-package-with-epoch.yaml @@ -0,0 +1,19 @@ +# yaml-language-server: $schema=https://nfpm.goreleaser.com/static/schema.json +--- +name: package-with-epoch +arch: all +platform: linux +version: 1.2.3 +section: default +priority: optional +maintainer: Your Name +description: Example package which uses the epoch field +homepage: https://thin-edge.io/ +license: MIT +epoch: "2" + +contents: + # reuse an existing file for convenience + - src: ./sampledeb_1.cfg + dst: /etc/package-with-epoch/ + type: config diff --git a/tests/RobotFramework/tests/plugin_apt/package-with-epoch_1.2.3_all.deb b/tests/RobotFramework/tests/plugin_apt/package-with-epoch_1.2.3_all.deb new file mode 100644 index 0000000000000000000000000000000000000000..09d3d49c229eed819f8d8806bde1590803a72a1e GIT binary patch literal 774 zcmY$iNi0gvu;WTeP0CEn(@o0EODw8XP*5;5H!wFcv@kR_R8TMg@?oT*fq|KciGl(U zK|unSk)8opa(-S(QGSkINn(*+dKF>)#+DFM6%-P<L-_7_BF`$n)IpWU)9ELxod~5J?85@+wJ3#U?luQZI4mn zDZ?Lk%M_I4Zk6?RR7h@od24RQQ^x2(^U}@EjdPF4K4>%jo8%ek-e7;O_~xCd1*^}B z*DA4ouH3l4{N}q%zGIvEMJ97kZi?cJ``mVS;>p);{>^bUY1=QhzWCJKWbohO;=H|G z$9DOs=}#2Ncz?6{?Xop@T>=j--{A6NfqT<){>08XZg2m1|5|nYrm%Tp&B1%Vn%VDH z-oL*ye+k3Q+Xk2Rh-DVfo4jgO&fP7`|GC_0?b^F6Wzp>OOZQqn|8aAtkXS5gvWOxFwVV3@w340}N1Na8m5LW(9%P zNG|Ds^a+hm?-XceU6${;RPx*R>)9h_zE_Ww?3=FG*mC&iiS7wCiean_2ZVTq8I~1C zELLNd3SH^N*b$bgn0YrsdAr?CKd*~NXT;5|-fmxe$4}z#_H*-NWHyzyoImZ4 z(EQ)aFKzhmJLBv9-QLxF?H~TP?_B>X|6Rqm#4Yo__czxYxnx}63Ro~jv}m$W{hj^& e*S(VV&ECUv*x-zj4HL-gZv(>iGw?7lZ~*{#9!v26 literal 0 HcmV?d00001