Skip to content

Commit

Permalink
Add test for handling special characters in module version
Browse files Browse the repository at this point in the history
Signed-off-by: Krzysztof Piotrowski <[email protected]>
  • Loading branch information
Ruadhri17 committed Feb 6, 2024
1 parent 6df6469 commit fed8e29
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/core/plugin_sm/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ pub fn deserialize_module_info(
Ok(software_list)
}

fn sm_path(name: &str, version: &Option<String>, target_dir_path: impl AsRef<Path>) -> PathBuf {
pub fn sm_path(name: &str, version: &Option<String>, target_dir_path: impl AsRef<Path>) -> PathBuf {
let mut filename = name.to_string();
if let Some(version) = version {
filename.push('_');
Expand Down
14 changes: 14 additions & 0 deletions crates/core/plugin_sm/tests/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>,
target_dir_path: impl AsRef<Path>,
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();
Expand Down
8 changes: 6 additions & 2 deletions tests/RobotFramework/tests/plugin_apt/build.sh
Original file line number Diff line number Diff line change
@@ -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 ||:
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions tests/RobotFramework/tests/plugin_apt/nfpm-package-with-epoch.yaml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
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
Binary file not shown.

0 comments on commit fed8e29

Please sign in to comment.