Merge pull request #1323 from matthiasbeyer/do-not-have-to-update-version-numbers-in-tests
Replace hard coded version strings with compiletime env
This commit is contained in:
commit
a0b989efdf
7 changed files with 65 additions and 64 deletions
|
@ -315,7 +315,7 @@ mod tests {
|
||||||
make_mock_app! {
|
make_mock_app! {
|
||||||
app "imag-link";
|
app "imag-link";
|
||||||
modulename mock;
|
modulename mock;
|
||||||
version "0.7.0";
|
version env!("CARGO_PKG_VERSION");
|
||||||
with help "imag-link mocking app";
|
with help "imag-link mocking app";
|
||||||
}
|
}
|
||||||
use self::mock::generate_test_runtime;
|
use self::mock::generate_test_runtime;
|
||||||
|
|
|
@ -174,7 +174,7 @@ mod tests {
|
||||||
make_mock_app! {
|
make_mock_app! {
|
||||||
app "imag-store";
|
app "imag-store";
|
||||||
modulename mock;
|
modulename mock;
|
||||||
version "0.7.0";
|
version env!("CARGO_PKG_VERSION");
|
||||||
with help "imag-store mocking app";
|
with help "imag-store mocking app";
|
||||||
}
|
}
|
||||||
use self::mock::generate_test_runtime;
|
use self::mock::generate_test_runtime;
|
||||||
|
@ -193,7 +193,7 @@ mod tests {
|
||||||
let e = e.unwrap();
|
let e = e.unwrap();
|
||||||
|
|
||||||
let version = e.get_header().read("imag.version").map(Option::unwrap).unwrap();
|
let version = e.get_header().read("imag.version").map(Option::unwrap).unwrap();
|
||||||
assert_eq!(Value::String(String::from("0.7.0")), *version);
|
assert_eq!(Value::String(String::from(env!("CARGO_PKG_VERSION"))), *version);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ mod tests {
|
||||||
make_mock_app! {
|
make_mock_app! {
|
||||||
app "imag-store";
|
app "imag-store";
|
||||||
modulename mock;
|
modulename mock;
|
||||||
version "0.7.0";
|
version env!("CARGO_PKG_VERSION");
|
||||||
with help "imag-store mocking app";
|
with help "imag-store mocking app";
|
||||||
}
|
}
|
||||||
use self::mock::generate_test_runtime;
|
use self::mock::generate_test_runtime;
|
||||||
|
|
|
@ -240,7 +240,7 @@ mod tests {
|
||||||
make_mock_app! {
|
make_mock_app! {
|
||||||
app "imag-tag";
|
app "imag-tag";
|
||||||
modulename mock;
|
modulename mock;
|
||||||
version "0.7.0";
|
version env!("CARGO_PKG_VERSION");
|
||||||
with help "imag-tag mocking app";
|
with help "imag-tag mocking app";
|
||||||
}
|
}
|
||||||
use self::mock::generate_test_runtime;
|
use self::mock::generate_test_runtime;
|
||||||
|
|
|
@ -112,11 +112,11 @@ mod test {
|
||||||
let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
|
let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
|
||||||
|
|
||||||
let loca = StoreId::new_baseless(path).unwrap();
|
let loca = StoreId::new_baseless(path).unwrap();
|
||||||
let file = Entry::from_str(loca.clone(), r#"---
|
let file = Entry::from_str(loca.clone(), &format!(r#"---
|
||||||
[imag]
|
[imag]
|
||||||
version = "0.7.0"
|
version = "{}"
|
||||||
---
|
---
|
||||||
Hello World"#).unwrap();
|
Hello World"#, env!("CARGO_PKG_VERSION"))).unwrap();
|
||||||
|
|
||||||
lf.write_file_content(&file).unwrap();
|
lf.write_file_content(&file).unwrap();
|
||||||
let bah = lf.get_file_content(loca).unwrap();
|
let bah = lf.get_file_content(loca).unwrap();
|
||||||
|
@ -132,12 +132,12 @@ Hello World"#).unwrap();
|
||||||
let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
|
let mut lf = InMemoryFileAbstractionInstance::new(fs.backend().clone(), path.clone());
|
||||||
|
|
||||||
let loca = StoreId::new_baseless(path).unwrap();
|
let loca = StoreId::new_baseless(path).unwrap();
|
||||||
let file = Entry::from_str(loca.clone(), r#"---
|
let file = Entry::from_str(loca.clone(), &format!(r#"---
|
||||||
[imag]
|
[imag]
|
||||||
version = "0.7.0"
|
version = "{}"
|
||||||
---
|
---
|
||||||
Hello World
|
Hello World
|
||||||
baz"#).unwrap();
|
baz"#, env!("CARGO_PKG_VERSION"))).unwrap();
|
||||||
|
|
||||||
lf.write_file_content(&file).unwrap();
|
lf.write_file_content(&file).unwrap();
|
||||||
let bah = lf.get_file_content(loca).unwrap();
|
let bah = lf.get_file_content(loca).unwrap();
|
||||||
|
|
|
@ -164,7 +164,8 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_empty_json_to_fs() {
|
fn test_empty_json_to_fs() {
|
||||||
let json = r#"{"version":"0.7.0","store":{}}"#;
|
let json = format!(r#"{{"version":"{version}","store":{{}}}}"#,
|
||||||
|
version = env!("CARGO_PKG_VERSION"));
|
||||||
let mut json = Cursor::new(String::from(json).into_bytes());
|
let mut json = Cursor::new(String::from(json).into_bytes());
|
||||||
let mapper = JsonMapper::new();
|
let mapper = JsonMapper::new();
|
||||||
let mut hm = HashMap::new();
|
let mut hm = HashMap::new();
|
||||||
|
@ -176,20 +177,20 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_json_to_fs() {
|
fn test_json_to_fs() {
|
||||||
let json = r#"
|
let json = format!(r#"
|
||||||
{ "version": "0.7.0",
|
{{ "version": "{version}",
|
||||||
"store": {
|
"store": {{
|
||||||
"example": {
|
"example": {{
|
||||||
"header": {
|
"header": {{
|
||||||
"imag": {
|
"imag": {{
|
||||||
"version": "0.7.0"
|
"version": "{version}"
|
||||||
}
|
}}
|
||||||
},
|
}},
|
||||||
"content": "test"
|
"content": "test"
|
||||||
}
|
}}
|
||||||
}
|
}}
|
||||||
}
|
}}
|
||||||
"#;
|
"#, version = env!("CARGO_PKG_VERSION"));
|
||||||
let mut json = Cursor::new(String::from(json).into_bytes());
|
let mut json = Cursor::new(String::from(json).into_bytes());
|
||||||
let mapper = JsonMapper::new();
|
let mapper = JsonMapper::new();
|
||||||
let mut hm = HashMap::new();
|
let mut hm = HashMap::new();
|
||||||
|
@ -207,14 +208,14 @@ mod test {
|
||||||
|
|
||||||
let mut hm = {
|
let mut hm = {
|
||||||
let mut hm = HashMap::new();
|
let mut hm = HashMap::new();
|
||||||
let content = r#"---
|
let content = format!(r#"---
|
||||||
[imag]
|
[imag]
|
||||||
version = "0.7.0"
|
version = "{}"
|
||||||
---
|
---
|
||||||
hi there!"#;
|
hi there!"#, env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
let id = PathBuf::from("example");
|
let id = PathBuf::from("example");
|
||||||
let entry = Entry::from_str(id.clone(), content).unwrap();
|
let entry = Entry::from_str(id.clone(), &content).unwrap();
|
||||||
hm.insert(id, entry);
|
hm.insert(id, entry);
|
||||||
hm
|
hm
|
||||||
};
|
};
|
||||||
|
@ -222,23 +223,23 @@ hi there!"#;
|
||||||
let io_res = mapper.fs_to_write(&mut hm, &mut out);
|
let io_res = mapper.fs_to_write(&mut hm, &mut out);
|
||||||
assert!(io_res.is_ok());
|
assert!(io_res.is_ok());
|
||||||
|
|
||||||
let example = r#"
|
let example = format!(r#"
|
||||||
{
|
{{
|
||||||
"version": "0.7.0",
|
"version": "{version}",
|
||||||
"store": {
|
"store": {{
|
||||||
"example": {
|
"example": {{
|
||||||
"header": {
|
"header": {{
|
||||||
"imag": {
|
"imag": {{
|
||||||
"version": "0.7.0"
|
"version": "{version}"
|
||||||
}
|
}}
|
||||||
},
|
}},
|
||||||
"content": "hi there!"
|
"content": "hi there!"
|
||||||
}
|
}}
|
||||||
}
|
}}
|
||||||
}
|
}}
|
||||||
"#;
|
"#, version = env!("CARGO_PKG_VERSION"));
|
||||||
|
|
||||||
let example_json : ::serde_json::Value = ::serde_json::from_str(example).unwrap();
|
let example_json : ::serde_json::Value = ::serde_json::from_str(&example).unwrap();
|
||||||
|
|
||||||
let output_json = String::from_utf8(out.into_inner()).unwrap();
|
let output_json = String::from_utf8(out.into_inner()).unwrap();
|
||||||
let output_json : ::serde_json::Value = ::serde_json::from_str(&output_json).unwrap();
|
let output_json : ::serde_json::Value = ::serde_json::from_str(&output_json).unwrap();
|
||||||
|
|
|
@ -1284,11 +1284,11 @@ mod store_tests {
|
||||||
use file_abstraction::stdio::mapper::json::JsonMapper;
|
use file_abstraction::stdio::mapper::json::JsonMapper;
|
||||||
|
|
||||||
// Lets have an empty store as input
|
// Lets have an empty store as input
|
||||||
let mut input = Cursor::new(r#"
|
let mut input = Cursor::new(format!(r#"
|
||||||
{ "version": "0.7.0",
|
{{ "version": "{}",
|
||||||
"store": { }
|
"store": {{}}
|
||||||
}
|
}}
|
||||||
"#);
|
"#, env!("CARGO_PKG_VERSION")));
|
||||||
|
|
||||||
let mapper = JsonMapper::new();
|
let mapper = JsonMapper::new();
|
||||||
let backend = StdIoFileAbstraction::new(&mut input, output.clone(), mapper).unwrap();
|
let backend = StdIoFileAbstraction::new(&mut input, output.clone(), mapper).unwrap();
|
||||||
|
@ -1322,7 +1322,7 @@ mod store_tests {
|
||||||
Value::Object(ref map) => {
|
Value::Object(ref map) => {
|
||||||
assert!(map.get("version").is_some(), format!("No 'version' in JSON"));
|
assert!(map.get("version").is_some(), format!("No 'version' in JSON"));
|
||||||
match map.get("version").unwrap() {
|
match map.get("version").unwrap() {
|
||||||
&Value::String(ref s) => assert_eq!("0.7.0", s),
|
&Value::String(ref s) => assert_eq!(env!("CARGO_PKG_VERSION"), s),
|
||||||
_ => panic!("Wrong type in JSON at 'version'"),
|
_ => panic!("Wrong type in JSON at 'version'"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1622,20 +1622,20 @@ mod store_tests {
|
||||||
use file_abstraction::stdio::mapper::json::JsonMapper;
|
use file_abstraction::stdio::mapper::json::JsonMapper;
|
||||||
|
|
||||||
// Lets have an empty store as input
|
// Lets have an empty store as input
|
||||||
let mut input = Cursor::new(r#"
|
let mut input = Cursor::new(format!(r#"
|
||||||
{ "version": "0.7.0",
|
{{ "version": "{version}",
|
||||||
"store": {
|
"store": {{
|
||||||
"example": {
|
"example": {{
|
||||||
"header": {
|
"header": {{
|
||||||
"imag": {
|
"imag": {{
|
||||||
"version": "0.7.0"
|
"version": "{version}"
|
||||||
}
|
}}
|
||||||
},
|
}},
|
||||||
"content": "foobar"
|
"content": "foobar"
|
||||||
}
|
}}
|
||||||
}
|
}}
|
||||||
}
|
}}
|
||||||
"#);
|
"#, version = env!("CARGO_PKG_VERSION")));
|
||||||
|
|
||||||
let output = Rc::new(RefCell::new(::std::io::sink()));
|
let output = Rc::new(RefCell::new(::std::io::sink()));
|
||||||
let mapper = JsonMapper::new();
|
let mapper = JsonMapper::new();
|
||||||
|
@ -1672,7 +1672,7 @@ mod store_tests {
|
||||||
Value::Object(ref map) => {
|
Value::Object(ref map) => {
|
||||||
assert!(map.get("version").is_some(), format!("No 'version' in JSON"));
|
assert!(map.get("version").is_some(), format!("No 'version' in JSON"));
|
||||||
match map.get("version").unwrap() {
|
match map.get("version").unwrap() {
|
||||||
&Value::String(ref s) => assert_eq!("0.7.0", s),
|
&Value::String(ref s) => assert_eq!(env!("CARGO_PKG_VERSION"), s),
|
||||||
_ => panic!("Wrong type in JSON at 'version'"),
|
_ => panic!("Wrong type in JSON at 'version'"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue