Merge changes from topic "aconfig-package-ident-fixes"
* changes: aconfig: package fields must contain at least one dot char aconfig: fix incorrect check in create_device_config_ident aconfig: improve package identifier test readability
This commit is contained in:
@@ -32,12 +32,15 @@ pub fn is_valid_name_ident(s: &str) -> bool {
|
||||
}
|
||||
|
||||
pub fn is_valid_package_ident(s: &str) -> bool {
|
||||
if !s.contains('.') {
|
||||
return false;
|
||||
}
|
||||
s.split('.').all(is_valid_name_ident)
|
||||
}
|
||||
|
||||
pub fn create_device_config_ident(package: &str, flag_name: &str) -> Result<String> {
|
||||
ensure!(is_valid_package_ident(package), "bad package");
|
||||
ensure!(is_valid_package_ident(flag_name), "bad flag name");
|
||||
ensure!(is_valid_name_ident(flag_name), "bad flag name");
|
||||
Ok(format!("{}.{}", package, flag_name))
|
||||
}
|
||||
|
||||
@@ -61,12 +64,13 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_is_valid_package_ident() {
|
||||
assert!(is_valid_package_ident("foo"));
|
||||
assert!(is_valid_package_ident("foo_bar_123"));
|
||||
assert!(is_valid_package_ident("foo.bar"));
|
||||
assert!(is_valid_package_ident("foo.bar_baz"));
|
||||
assert!(is_valid_package_ident("foo.bar.a123"));
|
||||
assert!(!is_valid_package_ident("foo._bar"));
|
||||
|
||||
assert!(!is_valid_package_ident("foo_bar_123"));
|
||||
assert!(!is_valid_package_ident("foo"));
|
||||
assert!(!is_valid_package_ident("foo._bar"));
|
||||
assert!(!is_valid_package_ident(""));
|
||||
assert!(!is_valid_package_ident("123_foo"));
|
||||
assert!(!is_valid_package_ident("foo-bar"));
|
||||
@@ -75,6 +79,7 @@ mod tests {
|
||||
assert!(!is_valid_package_ident(".foo.bar"));
|
||||
assert!(!is_valid_package_ident("foo.bar."));
|
||||
assert!(!is_valid_package_ident("."));
|
||||
assert!(!is_valid_package_ident(".."));
|
||||
assert!(!is_valid_package_ident("foo..bar"));
|
||||
assert!(!is_valid_package_ident("foo.__bar"));
|
||||
}
|
||||
|
@@ -549,7 +549,7 @@ parsed_flag {
|
||||
// bad input: parsed_flag not sorted by package
|
||||
let text_proto = r#"
|
||||
parsed_flag {
|
||||
package: "bbb"
|
||||
package: "bbb.bbb"
|
||||
name: "first"
|
||||
namespace: "first_ns"
|
||||
description: "This is the description of the first flag."
|
||||
@@ -562,7 +562,7 @@ parsed_flag {
|
||||
}
|
||||
}
|
||||
parsed_flag {
|
||||
package: "aaa"
|
||||
package: "aaa.aaa"
|
||||
name: "second"
|
||||
namespace: "second_ns"
|
||||
description: "This is the description of the second flag."
|
||||
@@ -578,7 +578,7 @@ parsed_flag {
|
||||
let error = try_from_binary_proto_from_text_proto(text_proto).unwrap_err();
|
||||
assert_eq!(
|
||||
format!("{:?}", error),
|
||||
"bad parsed flags: not sorted: bbb.first comes before aaa.second"
|
||||
"bad parsed flags: not sorted: bbb.bbb.first comes before aaa.aaa.second"
|
||||
);
|
||||
|
||||
// bad input: parsed_flag not sorted by name
|
||||
|
Reference in New Issue
Block a user