mirror of
https://codeberg.org/Toasterson/ips.git
synced 2026-04-10 13:20:42 +00:00
Fix tests with pest parsing
This commit is contained in:
parent
48525d3122
commit
991ea1d86c
3 changed files with 83 additions and 45 deletions
|
|
@ -61,7 +61,7 @@ transform_character = {
|
||||||
transform_action = @{ transform_character*}
|
transform_action = @{ transform_character*}
|
||||||
transform = {"<transform " ~ action_name ~ property+ ~ " "? ~ "->" ~ " "? ~ transform_action ~ ">" }
|
transform = {"<transform " ~ action_name ~ property+ ~ " "? ~ "->" ~ " "? ~ transform_action ~ ">" }
|
||||||
|
|
||||||
property_name = @{ ( ASCII_ALPHANUMERIC | "." | "_" )+ }
|
property_name = @{ ( ASCII_ALPHANUMERIC | "." | "_" | "-" )+ }
|
||||||
property_value = @{ ( ASCII_ALPHANUMERIC | "/" | "," | "." | "_" | "-" | "%" | "*" | "@" | "(" | ")" | "$" | ":" | "+" )+ | quoted_string }
|
property_value = @{ ( ASCII_ALPHANUMERIC | "/" | "," | "." | "_" | "-" | "%" | "*" | "@" | "(" | ")" | "$" | ":" | "+" )+ | quoted_string }
|
||||||
payload = @{ payload_character* }
|
payload = @{ payload_character* }
|
||||||
property = { " "? ~ property_name ~ "=" ~ property_value }
|
property = { " "? ~ property_name ~ "=" ~ property_value }
|
||||||
|
|
|
||||||
|
|
@ -72,17 +72,26 @@ pub struct Dir {
|
||||||
impl From<Action> for Dir {
|
impl From<Action> for Dir {
|
||||||
fn from(act: Action) -> Self {
|
fn from(act: Action) -> Self {
|
||||||
let mut dir = Dir::default();
|
let mut dir = Dir::default();
|
||||||
for prop in act.properties {
|
let mut props = act.properties;
|
||||||
|
if !act.payload_string.is_empty() {
|
||||||
|
let p_str = split_property(act.payload_string);
|
||||||
|
props.push(Property{
|
||||||
|
key: p_str.0,
|
||||||
|
value: p_str.1.replace("\"", ""),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for prop in props {
|
||||||
|
let cleaned_value = prop.value.replace("\"", "");
|
||||||
match prop.key.as_str() {
|
match prop.key.as_str() {
|
||||||
"path" => dir.path = prop.value,
|
"path" => dir.path = cleaned_value,
|
||||||
"owner" => dir.owner = prop.value,
|
"owner" => dir.owner = cleaned_value,
|
||||||
"group" => dir.group = prop.value,
|
"group" => dir.group = cleaned_value,
|
||||||
"mode" => dir.mode = prop.value,
|
"mode" => dir.mode = cleaned_value,
|
||||||
"revert-tag" => dir.revert_tag = prop.value,
|
"revert-tag" => dir.revert_tag = cleaned_value,
|
||||||
"salvage-from" => dir.salvage_from = prop.value,
|
"salvage-from" => dir.salvage_from = cleaned_value,
|
||||||
_ => {
|
_ => {
|
||||||
if is_facet(prop.key.clone()) {
|
if is_facet(prop.key.clone()) {
|
||||||
dir.add_facet(Facet::from_key_value(prop.key, prop.value));
|
dir.add_facet(Facet::from_key_value(prop.key, cleaned_value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,39 +151,44 @@ impl From<Action> for File {
|
||||||
if act.payload_string.contains("/") {
|
if act.payload_string.contains("/") {
|
||||||
file.properties.push(Property{
|
file.properties.push(Property{
|
||||||
key: "original-path".to_string(),
|
key: "original-path".to_string(),
|
||||||
value: act.payload_string
|
value: act.payload_string.replace("\"", "")
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
p.primary_identifier = Digest::from_str(&act.payload_string).unwrap();
|
p.primary_identifier = Digest::from_str(&act.payload_string).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for prop in act.properties {
|
for prop in act.properties {
|
||||||
|
let cleaned_value = prop.value.replace("\"", "");
|
||||||
match prop.key.as_str() {
|
match prop.key.as_str() {
|
||||||
"path" => file.path = prop.value,
|
"path" => file.path = cleaned_value,
|
||||||
"owner" => file.owner = prop.value,
|
"owner" => file.owner = cleaned_value,
|
||||||
"group" => file.group = prop.value,
|
"group" => file.group = cleaned_value,
|
||||||
"mode" => file.mode = prop.value,
|
"mode" => file.mode = cleaned_value,
|
||||||
"revert-tag" => file.revert_tag = prop.value,
|
"revert-tag" => file.revert_tag = cleaned_value,
|
||||||
"original_name" => file.original_name = prop.value,
|
"original_name" => file.original_name = cleaned_value,
|
||||||
"sysattr" => file.sys_attr = prop.value,
|
"sysattr" => file.sys_attr = cleaned_value,
|
||||||
"overlay" => file.overlay = match string_to_bool(&prop.value) {
|
"overlay" => file.overlay = match string_to_bool(&cleaned_value) {
|
||||||
Ok(b) => b,
|
Ok(b) => b,
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
"preserve" => file.preserve = match string_to_bool(&prop.value) {
|
"preserve" => file.preserve = match string_to_bool(&cleaned_value) {
|
||||||
Ok(b) => b,
|
Ok(b) => b,
|
||||||
_ => false,
|
_ => false,
|
||||||
},
|
},
|
||||||
"chash" | "pkg.content-hash" => p.additional_identifiers.push(Digest::from_str(&prop.value).unwrap()),
|
"chash" | "pkg.content-hash" => p.additional_identifiers.push(Digest::from_str(&cleaned_value).unwrap()),
|
||||||
_ => {
|
_ => {
|
||||||
if is_facet(prop.key.clone()) {
|
if is_facet(prop.key.clone()) {
|
||||||
file.add_facet(Facet::from_key_value(prop.key, prop.value));
|
file.add_facet(Facet::from_key_value(prop.key, cleaned_value));
|
||||||
} else {
|
} else {
|
||||||
file.properties.push(prop.clone());
|
file.properties.push(Property{
|
||||||
|
key: prop.key,
|
||||||
|
value: prop.value.replace("\"", "")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
file.payload = Some(p);
|
||||||
file
|
file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -209,15 +223,24 @@ pub struct Dependency {
|
||||||
impl From<Action> for Dependency {
|
impl From<Action> for Dependency {
|
||||||
fn from(act: Action) -> Self {
|
fn from(act: Action) -> Self {
|
||||||
let mut dep = Dependency::default();
|
let mut dep = Dependency::default();
|
||||||
for prop in act.properties {
|
let mut props = act.properties;
|
||||||
|
if !act.payload_string.is_empty() {
|
||||||
|
let p_str = split_property(act.payload_string);
|
||||||
|
props.push(Property{
|
||||||
|
key: p_str.0,
|
||||||
|
value: p_str.1.replace("\"", ""),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for prop in props {
|
||||||
|
let cleaned_value = prop.value.replace("\"", "");
|
||||||
match prop.key.as_str() {
|
match prop.key.as_str() {
|
||||||
"fmri" => dep.fmri = prop.value,
|
"fmri" => dep.fmri = cleaned_value,
|
||||||
"type" => dep.dependency_type = prop.value,
|
"type" => dep.dependency_type = cleaned_value,
|
||||||
"predicate" => dep.predicate = prop.value,
|
"predicate" => dep.predicate = cleaned_value,
|
||||||
"root-image" => dep.root_image = prop.value,
|
"root-image" => dep.root_image = cleaned_value,
|
||||||
_ => {
|
_ => {
|
||||||
if is_facet(prop.key.clone()) {
|
if is_facet(prop.key.clone()) {
|
||||||
dep.add_facet(Facet::from_key_value(prop.key, prop.value));
|
dep.add_facet(Facet::from_key_value(prop.key, cleaned_value));
|
||||||
} else {
|
} else {
|
||||||
dep.optional.push(prop.clone());
|
dep.optional.push(prop.clone());
|
||||||
}
|
}
|
||||||
|
|
@ -263,14 +286,23 @@ pub struct Attr {
|
||||||
impl From<Action> for Attr {
|
impl From<Action> for Attr {
|
||||||
fn from(act: Action) -> Self {
|
fn from(act: Action) -> Self {
|
||||||
let mut attr = Attr::default();
|
let mut attr = Attr::default();
|
||||||
for prop in act.properties {
|
let mut props = act.properties;
|
||||||
|
if !act.payload_string.is_empty() {
|
||||||
|
let p_str = split_property(act.payload_string);
|
||||||
|
props.push(Property{
|
||||||
|
key: p_str.0,
|
||||||
|
value: p_str.1.replace("\"", ""),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for prop in props {
|
||||||
|
let cleaned_value = prop.value.replace("\"", "");
|
||||||
match prop.key.as_str() {
|
match prop.key.as_str() {
|
||||||
"name" => attr.key = prop.value,
|
"name" => attr.key = cleaned_value,
|
||||||
"value" => attr.values.push(prop.value),
|
"value" => attr.values.push(cleaned_value),
|
||||||
_ => {
|
_ => {
|
||||||
attr.properties.insert(prop.key.clone(), Property{
|
attr.properties.insert(prop.key.clone(), Property{
|
||||||
key: prop.key,
|
key: prop.key,
|
||||||
value: prop.value
|
value: cleaned_value
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -476,6 +508,16 @@ fn get_facet_key(facet_string: String) -> String {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn split_property(property_string: String) -> (String, String) {
|
||||||
|
match property_string.find("=") {
|
||||||
|
Some(_) => {
|
||||||
|
let v :Vec <_> = property_string.split("=").collect();
|
||||||
|
(String::from(v[0]), String::from(v[1]))
|
||||||
|
},
|
||||||
|
None => (property_string.clone(), String::new())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn parse_manifest_file(filename: String) -> Result<Manifest> {
|
pub fn parse_manifest_file(filename: String) -> Result<Manifest> {
|
||||||
let mut m = Manifest::new();
|
let mut m = Manifest::new();
|
||||||
let f = OsFile::open(filename)?;
|
let f = OsFile::open(filename)?;
|
||||||
|
|
|
||||||
|
|
@ -165,10 +165,10 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn parse_direcory_actions() {
|
fn parse_direcory_actions() {
|
||||||
let manifest_string = String::from("dir group=bin mode=0755 owner=root path=etc/nginx
|
let manifest_string = String::from("dir group=bin mode=0755 owner=root path=etc/nginx
|
||||||
dir group=bin mode=0755 owner=root path=usr/share/nginx
|
dir group=bin mode=0755 owner=root path=usr/share/nginx
|
||||||
dir group=bin mode=0755 owner=root path=usr/share/nginx/html
|
dir group=bin mode=0755 owner=root path=usr/share/nginx/html
|
||||||
dir group=bin mode=0755 owner=webservd path=var/nginx/logs
|
dir group=bin mode=0755 owner=webservd path=var/nginx/logs
|
||||||
dir group=bin mode=0755 owner=root path=\"var/nginx\"");
|
dir group=bin mode=0755 owner=root path=\"var/nginx\"");
|
||||||
|
|
||||||
let test_results = vec![
|
let test_results = vec![
|
||||||
Dir{
|
Dir{
|
||||||
|
|
@ -204,14 +204,10 @@ mod tests {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut manifest = Manifest::new();
|
|
||||||
match parse_manifest_string(manifest_string) {
|
let res = Manifest::parse_string(manifest_string);
|
||||||
Ok(m) => manifest = m,
|
assert!(res.is_ok(), "error during Manifest parsing: {:?}", res);
|
||||||
Err(e) => {
|
let manifest = res.unwrap();
|
||||||
println!("{}", e);
|
|
||||||
assert!(false, "caught error");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
assert_eq!(manifest.directories.len(), test_results.len());
|
assert_eq!(manifest.directories.len(), test_results.len());
|
||||||
|
|
||||||
|
|
@ -811,7 +807,7 @@ file 6d5f820bb1d67594c7b757c79ef6f9242df49e98 chash=3ab17dde089f1eac7abd37d8efd7
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
let res = parse_manifest_string(manifest_string);
|
let res = Manifest::parse_string(manifest_string);
|
||||||
assert!(res.is_ok(), "error during Manifest parsing: {:?}", res);
|
assert!(res.is_ok(), "error during Manifest parsing: {:?}", res);
|
||||||
let manifest = res.unwrap();
|
let manifest = res.unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue