2020-05-17 21:52:39 +02:00
|
|
|
// This Source Code Form is subject to the terms of
|
|
|
|
|
// the Mozilla Public License, v. 2.0. If a copy of the
|
|
|
|
|
// MPL was not distributed with this file, You can
|
|
|
|
|
// obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
2020-05-17 01:17:19 +02:00
|
|
|
mod actions;
|
|
|
|
|
|
2020-05-18 16:57:21 +02:00
|
|
|
#[macro_use] extern crate failure;
|
|
|
|
|
|
2020-05-17 01:17:19 +02:00
|
|
|
#[cfg(test)]
|
|
|
|
|
mod tests {
|
|
|
|
|
|
2020-05-19 22:14:28 +02:00
|
|
|
use crate::actions::{Manifest, Property, Dir};
|
2020-05-18 10:32:16 +02:00
|
|
|
use crate::actions::{parse_manifest_string, Attr};
|
2020-05-17 22:02:35 +02:00
|
|
|
use std::collections::HashSet;
|
2020-05-17 01:17:19 +02:00
|
|
|
|
|
|
|
|
#[test]
|
2020-05-19 22:14:28 +02:00
|
|
|
fn parse_attributes() {
|
2020-05-17 01:17:19 +02:00
|
|
|
let manifest_string = String::from("set name=pkg.fmri value=pkg://openindiana.org/web/server/nginx@1.18.0,5.11-2020.0.1.0:20200421T195136Z
|
|
|
|
|
set name=com.oracle.info.name value=nginx value=test
|
|
|
|
|
set name=userland.info.git-remote value=git://github.com/OpenIndiana/oi-userland.git
|
|
|
|
|
set name=userland.info.git-branch value=HEAD
|
|
|
|
|
set name=userland.info.git-rev value=1665491ba61bd494bf73e2916cd2250f3024260e
|
|
|
|
|
set name=pkg.summary value=\"Nginx Webserver\"
|
|
|
|
|
set name=info.classification value=\"org.opensolaris.category.2008:Web Services/Application and Web Servers\"
|
|
|
|
|
set name=info.upstream-url value=http://nginx.net/
|
|
|
|
|
set name=info.source-url value=http://nginx.org/download/nginx-1.18.0.tar.gz
|
|
|
|
|
set name=org.opensolaris.consolidation value=userland
|
|
|
|
|
set name=com.oracle.info.version value=1.18.0
|
2020-05-18 14:57:55 +02:00
|
|
|
set name=pkg.summary value=\\\"provided mouse accessibility enhancements\\\"
|
|
|
|
|
set name=info.upstream value=X.Org Foundation
|
|
|
|
|
set name=pkg.description value=Latvian language support's extra files
|
2020-05-18 16:57:21 +02:00
|
|
|
set name=variant.arch value=i386 optional=testing optionalWithString=\"test ing\"
|
|
|
|
|
set name=info.source-url value=http://www.pgpool.net/download.php?f=pgpool-II-3.3.1.tar.gz
|
|
|
|
|
set name=pkg.summary value=\\\"'XZ Utils - loss-less file compression application and library.'\\\"");
|
2020-05-18 14:57:55 +02:00
|
|
|
|
|
|
|
|
let mut optional_hash = HashSet::new();
|
|
|
|
|
optional_hash.insert(Property{key: String::from("optional"), value:String::from("testing")});
|
|
|
|
|
optional_hash.insert(Property{key: String::from("optionalWithString"), value:String::from("test ing")});
|
|
|
|
|
|
2020-05-18 10:32:16 +02:00
|
|
|
let test_results = vec![
|
2020-05-17 21:52:39 +02:00
|
|
|
Attr{
|
|
|
|
|
key: String::from("pkg.fmri"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("pkg://openindiana.org/web/server/nginx@1.18.0,5.11-2020.0.1.0:20200421T195136Z")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("com.oracle.info.name"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("nginx"), String::from("test")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("userland.info.git-remote"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("git://github.com/OpenIndiana/oi-userland.git")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("userland.info.git-branch"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("HEAD")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("userland.info.git-rev"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("1665491ba61bd494bf73e2916cd2250f3024260e")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("pkg.summary"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("Nginx Webserver")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("info.classification"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("org.opensolaris.category.2008:Web Services/Application and Web Servers")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("info.upstream-url"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("http://nginx.net/")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("info.source-url"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("http://nginx.org/download/nginx-1.18.0.tar.gz")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("org.opensolaris.consolidation"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("userland")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("com.oracle.info.version"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("1.18.0")],
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
},
|
2020-05-18 14:57:55 +02:00
|
|
|
Attr{
|
|
|
|
|
key: String::from("pkg.summary"),
|
|
|
|
|
values: vec![String::from("provided mouse accessibility enhancements")],
|
|
|
|
|
properties: HashSet::new(),
|
|
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("info.upstream"),
|
|
|
|
|
values: vec![String::from("X.Org Foundation")],
|
|
|
|
|
properties: HashSet::new(),
|
|
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("pkg.description"),
|
|
|
|
|
values: vec![String::from("Latvian language support's extra files")],
|
|
|
|
|
properties: HashSet::new(),
|
|
|
|
|
},
|
2020-05-17 21:52:39 +02:00
|
|
|
Attr{
|
|
|
|
|
key: String::from("variant.arch"),
|
2020-05-17 22:02:35 +02:00
|
|
|
values: vec![String::from("i386")],
|
2020-05-18 14:57:55 +02:00
|
|
|
properties: optional_hash,
|
2020-05-18 16:57:21 +02:00
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("info.source-url"),
|
|
|
|
|
values: vec![String::from("http://www.pgpool.net/download.php?f=pgpool-II-3.3.1.tar.gz")],
|
|
|
|
|
properties: HashSet::new(),
|
|
|
|
|
},
|
|
|
|
|
Attr{
|
|
|
|
|
key: String::from("pkg.summary"),
|
|
|
|
|
values: vec![String::from("'XZ Utils - loss-less file compression application and library.'")], //TODO knock out the single quotes
|
|
|
|
|
properties: HashSet::new(),
|
2020-05-17 21:52:39 +02:00
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2020-05-18 10:32:16 +02:00
|
|
|
let mut manifest = Manifest::new();
|
|
|
|
|
match parse_manifest_string(manifest_string) {
|
2020-05-17 01:17:19 +02:00
|
|
|
Ok(m) => manifest = m,
|
2020-05-18 16:57:21 +02:00
|
|
|
Err(e) => {
|
|
|
|
|
println!("{}", e);
|
|
|
|
|
assert!(false, "caught error");
|
|
|
|
|
}
|
2020-05-17 01:17:19 +02:00
|
|
|
};
|
2020-05-18 14:57:55 +02:00
|
|
|
|
2020-05-18 16:57:21 +02:00
|
|
|
assert_eq!(manifest.attributes.len(), 17);
|
2020-05-18 14:57:55 +02:00
|
|
|
|
2020-05-17 21:52:39 +02:00
|
|
|
for (pos, attr) in manifest.attributes.iter().enumerate() {
|
2020-05-18 10:32:16 +02:00
|
|
|
assert_eq!(attr.key, test_results[pos].key);
|
2020-05-18 14:57:55 +02:00
|
|
|
|
2020-05-17 21:52:39 +02:00
|
|
|
for (vpos, val) in attr.values.iter().enumerate() {
|
2020-05-18 10:32:16 +02:00
|
|
|
assert_eq!(val, &test_results[pos].values[vpos]);
|
2020-05-17 01:17:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-19 22:14:28 +02:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn parse_direcory_actions() {
|
|
|
|
|
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/html
|
|
|
|
|
dir group=bin mode=0755 owner=root path=\"var/nginx\"
|
|
|
|
|
dir group=bin mode=0755 owner=webservd path=var/nginx/logs");
|
|
|
|
|
|
|
|
|
|
let test_results = vec![
|
|
|
|
|
Dir{
|
|
|
|
|
group: String::from("bin"),
|
|
|
|
|
mode: String::from("0755"),
|
|
|
|
|
owner: String::from("root"),
|
|
|
|
|
path: String::from("etc/nginx"),
|
|
|
|
|
..Dir::default()
|
|
|
|
|
},Dir{
|
|
|
|
|
group: String::from("bin"),
|
|
|
|
|
mode: String::from("0755"),
|
|
|
|
|
owner: String::from("root"),
|
|
|
|
|
path: String::from("usr/share/nginx"),
|
|
|
|
|
..Dir::default()
|
|
|
|
|
},Dir{
|
|
|
|
|
group: String::from("bin"),
|
|
|
|
|
mode: String::from("0755"),
|
|
|
|
|
owner: String::from("root"),
|
|
|
|
|
path: String::from("usr/share/nginx/html"),
|
|
|
|
|
..Dir::default()
|
|
|
|
|
},Dir{
|
|
|
|
|
group: String::from("bin"),
|
|
|
|
|
mode: String::from("0755"),
|
|
|
|
|
owner: String::from("root"),
|
|
|
|
|
path: String::from("\"var/nginx\""),
|
|
|
|
|
..Dir::default()
|
|
|
|
|
},Dir{
|
|
|
|
|
group: String::from("bin"),
|
|
|
|
|
mode: String::from("0755"),
|
|
|
|
|
owner: String::from("root"),
|
|
|
|
|
path: String::from("var/nginx/logs"),
|
|
|
|
|
..Dir::default()
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
let mut manifest = Manifest::new();
|
|
|
|
|
match parse_manifest_string(manifest_string) {
|
|
|
|
|
Ok(m) => manifest = m,
|
|
|
|
|
Err(e) => {
|
|
|
|
|
println!("{}", e);
|
|
|
|
|
assert!(false, "caught error");
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
assert_eq!(manifest.directories.len(), test_results.len());
|
|
|
|
|
|
|
|
|
|
for (pos, attr) in manifest.directories.iter().enumerate() {
|
|
|
|
|
assert_eq!(attr.group, test_results[pos].group);
|
|
|
|
|
assert_eq!(attr.mode, test_results[pos].mode);
|
|
|
|
|
assert_eq!(attr.owner, test_results[pos].owner);
|
|
|
|
|
assert_eq!(attr.path, test_results[pos].path);
|
|
|
|
|
|
|
|
|
|
//for (vpos, val) in attr.facets.iter().enumerate() {
|
|
|
|
|
// assert_eq!(val, &test_results[pos].facets.);
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-17 01:17:19 +02:00
|
|
|
}
|