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..f1e5b3c346c 100644 --- a/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot +++ b/tests/RobotFramework/tests/plugin_apt/install_overwrite_config_files.robot @@ -45,7 +45,6 @@ Install packages overwrite config files ${output}= Execute Command cat /etc/sampledeb.cfg Should Contain ${output} conf 2.0 - *** Keywords *** Custom Setup ${DEVICE_SN}= Setup diff --git a/tests/RobotFramework/tests/plugin_apt/install_package_with_epoch.robot b/tests/RobotFramework/tests/plugin_apt/install_package_with_epoch.robot new file mode 100644 index 00000000000..c2114fb872a --- /dev/null +++ b/tests/RobotFramework/tests/plugin_apt/install_package_with_epoch.robot @@ -0,0 +1,21 @@ +*** Settings *** +Resource ../../resources/common.resource +Library ThinEdgeIO +Library Cumulocity + +Test Setup Custom Setup +Test Teardown Get Logs + +Test Tags theme:software theme:plugins + +*** Test Cases *** +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 + ${DEVICE_SN}= Setup + Device Should Exist ${DEVICE_SN} \ No newline at end of file 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..8936072e5aa --- /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: thin-edge.io +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/nfpm-version1.yaml b/tests/RobotFramework/tests/plugin_apt/nfpm-version1.yaml index d825e43485d..6e85839382e 100644 --- a/tests/RobotFramework/tests/plugin_apt/nfpm-version1.yaml +++ b/tests/RobotFramework/tests/plugin_apt/nfpm-version1.yaml @@ -4,7 +4,7 @@ platform: linux version: 1.0.0 section: default priority: optional -maintainer: Your Name +maintainer: thin-edge.io description: My Sample App Debian Package homepage: https://example.com/myapp license: MIT diff --git a/tests/RobotFramework/tests/plugin_apt/nfpm-version2.yaml b/tests/RobotFramework/tests/plugin_apt/nfpm-version2.yaml index a3f228756da..ca7128b3147 100644 --- a/tests/RobotFramework/tests/plugin_apt/nfpm-version2.yaml +++ b/tests/RobotFramework/tests/plugin_apt/nfpm-version2.yaml @@ -4,7 +4,7 @@ platform: linux version: 2.0.0 section: default priority: optional -maintainer: Your Name +maintainer: thin-edge.io description: My Sample App Debian Package homepage: https://example.com/myapp license: MIT 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 00000000000..c6584fc0ae2 Binary files /dev/null and b/tests/RobotFramework/tests/plugin_apt/package-with-epoch_1.2.3_all.deb differ diff --git a/tests/RobotFramework/tests/plugin_apt/sampledeb_1.0.0_all.deb b/tests/RobotFramework/tests/plugin_apt/sampledeb_1.0.0_all.deb index 656be4302d2..332b865212e 100644 Binary files a/tests/RobotFramework/tests/plugin_apt/sampledeb_1.0.0_all.deb and b/tests/RobotFramework/tests/plugin_apt/sampledeb_1.0.0_all.deb differ diff --git a/tests/RobotFramework/tests/plugin_apt/sampledeb_2.0.0_all.deb b/tests/RobotFramework/tests/plugin_apt/sampledeb_2.0.0_all.deb index eec5c1ecbdd..032a52dd749 100644 Binary files a/tests/RobotFramework/tests/plugin_apt/sampledeb_2.0.0_all.deb and b/tests/RobotFramework/tests/plugin_apt/sampledeb_2.0.0_all.deb differ diff --git a/tests/images/debian-systemd/files/tedge.toml b/tests/images/debian-systemd/files/tedge.toml index c71266b77d7..96a34195a3d 100644 --- a/tests/images/debian-systemd/files/tedge.toml +++ b/tests/images/debian-systemd/files/tedge.toml @@ -1,3 +1,4 @@ [apt] name = "(tedge|c8y|python|wget|vim|curl|apt|mosquitto|ssh|sudo|rolldice).*" +maintainer = ".*(thin-edge.io).*" \ No newline at end of file