Commit e64be069 authored by Alexis Janon's avatar Alexis Janon
Browse files

Integration test cleanup

Now contains a constant json command correctly escaped, and has no
unused code or return values.
parent d0a627fe
extern crate cuttr;
use std::env;
use std::fs;
use std::path;
use std::rc::Rc;
......@@ -16,47 +15,61 @@ const PROPERTY: &str = "cpuset.cpus";
const CONTROLLER: &str = "cpuset";
const VALUE: &str = "0";
#[allow(unused_must_use)]
#[test]
fn test_create() {
let mut json = r#"{"commands":[{"command":"create","name":""#.to_owned();
json.push_str(CREATE_NAME);
json.push_str(r#""}]}"#);
let json = format!(
r#"
{{
"commands":[
{{
"command":"create",
"name":"{}"
}}
]
}}
"#,
CREATE_NAME
);
let controllers = Rc::new(configuration::sysfscontroller::get_sys_fs_controllers().unwrap());
let paths = controllers
.values()
.map(SysFsController::get_path)
.map(path::Path::to_path_buf)
.map(|mut p| {
p.push(CREATE_NAME);
p
}).collect::<Vec<_>>();
.map(|path| path.join(CREATE_NAME))
.collect::<Vec<_>>();
let mut commands = parsing::parse_json(&json, controllers).unwrap();
assert!(commands.exec().is_ok());
let result = paths.iter().all(|p| p.exists());
for path in paths.iter().filter(|p| p.exists()) {
fs::remove_dir(&path);
assert!(fs::remove_dir(&path).is_ok());
}
assert!(result);
}
#[allow(unused_must_use)]
#[test]
fn test_remove() {
let mut json = r#"{"commands":[{"command":"remove","name":""#.to_owned();
json.push_str(DELETE_NAME);
json.push_str(r#""}]}"#);
let json = format!(
r#"
{{
"commands":[
{{
"command":"remove",
"name":"{}"
}}
]
}}
"#,
DELETE_NAME
);
let controllers = Rc::new(configuration::sysfscontroller::get_sys_fs_controllers().unwrap());
let paths = controllers
.values()
.map(SysFsController::get_path)
.map(path::Path::to_path_buf)
.map(|mut p| {
p.push(DELETE_NAME);
p
}).collect::<Vec<_>>();
.map(|path| path.join(DELETE_NAME))
.collect::<Vec<_>>();
for path in &paths {
fs::create_dir(&path);
assert!(fs::create_dir(&path).is_ok());
}
let mut commands = parsing::parse_json(&json, controllers).unwrap();
assert!(commands.exec().is_ok());
......@@ -64,28 +77,34 @@ fn test_remove() {
assert!(result);
}
#[allow(unused_must_use)]
#[test]
// TODO: need cpuset cgroup: make it more generic (or robust)
fn test_modify() {
let mut json = r#"{"commands":[{"command":"modify","name":""#.to_owned();
json.push_str(MODIFY_NAME);
json.push_str(r#"", "properties":{""#);
json.push_str(PROPERTY);
json.push_str(r#"":""#);
json.push_str(VALUE);
json.push_str(r#""}}]}"#);
let json = format!(
r#"
{{
"commands":[
{{
"command":"modify",
"name":"{}",
"properties":{{
"{}":"{}"
}}
}}
]
}}
"#,
MODIFY_NAME, PROPERTY, VALUE
);
let controllers = Rc::new(configuration::sysfscontroller::get_sys_fs_controllers().unwrap());
let paths = controllers
.values()
.map(SysFsController::get_path)
.map(path::Path::to_path_buf)
.map(|mut p| {
p.push(MODIFY_NAME);
p
}).collect::<Vec<_>>();
.map(|path| path.join(MODIFY_NAME))
.collect::<Vec<_>>();
for path in &paths {
fs::create_dir(&path);
assert!(fs::create_dir(&path).is_ok());
}
let mut commands = parsing::parse_json(&json, Rc::clone(&controllers)).unwrap();
assert!(commands.exec().is_ok());
......@@ -94,32 +113,38 @@ fn test_modify() {
cpuset.push(PROPERTY);
assert_eq!(fs::read_to_string(cpuset).unwrap().trim(), VALUE);
for path in paths.iter().filter(|p| p.exists()) {
fs::remove_dir(&path);
assert!(fs::remove_dir(&path).is_ok());
}
}
#[allow(unused_must_use)]
#[test]
// TODO: need cpuset cgroup: make it more generic (or robust)
fn test_create_with_properties() {
let mut json = r#"{"commands":[{"command":"modify","name":""#.to_owned();
json.push_str(CREATE_WITH_PROPERTIES_NAME);
json.push_str(r#"", "properties":{""#);
json.push_str(PROPERTY);
json.push_str(r#"":""#);
json.push_str(VALUE);
json.push_str(r#""}}]}"#);
let json = format!(
r#"
{{
"commands":[
{{
"command":"create",
"name":"{}",
"properties":{{
"{}":"{}"
}}
}}
]
}}
"#,
CREATE_WITH_PROPERTIES_NAME, PROPERTY, VALUE
);
let controllers = Rc::new(configuration::sysfscontroller::get_sys_fs_controllers().unwrap());
let paths = controllers
.values()
.map(SysFsController::get_path)
.map(path::Path::to_path_buf)
.map(|mut p| {
p.push(CREATE_WITH_PROPERTIES_NAME);
p
}).collect::<Vec<_>>();
.map(|path| path.join(CREATE_WITH_PROPERTIES_NAME))
.collect::<Vec<_>>();
for path in &paths {
fs::create_dir(&path);
assert!(fs::create_dir(&path).is_ok());
}
let mut commands = parsing::parse_json(&json, Rc::clone(&controllers)).unwrap();
assert!(commands.exec().is_ok());
......@@ -128,6 +153,6 @@ fn test_create_with_properties() {
cpuset.push(PROPERTY);
assert_eq!(fs::read_to_string(cpuset).unwrap().trim(), VALUE);
for path in paths.iter().filter(|p| p.exists()) {
fs::remove_dir(&path);
assert!(fs::remove_dir(&path).is_ok());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment