-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
306 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,3 +419,193 @@ fn test_try_merge_partman() -> Result<(), Box<dyn Error>> { | |
|
||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_spec() { | ||
for (name, json) in [ | ||
( | ||
"both", | ||
json!({"version": "2.0.0", "url": "https://example.com"}), | ||
), | ||
("version only", json!({"version": "2.0.4"})), | ||
] { | ||
let spec: Spec = serde_json::from_value(json.clone()).unwrap(); | ||
assert_eq!( | ||
json.get("version").unwrap().as_str().unwrap(), | ||
spec.version().to_string(), | ||
"{name}", | ||
); | ||
match json.get("url") { | ||
None => assert!(spec.url().is_none()), | ||
Some(url) => assert_eq!(url.as_str().unwrap(), spec.url().unwrap()), | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_maintainer() { | ||
for (name, json) in [ | ||
( | ||
"all fields", | ||
json!({ | ||
"name": "Barrack Obama", | ||
"email": "[email protected]", | ||
"url": "https://potus.example.com", | ||
}), | ||
), | ||
( | ||
"name and email", | ||
json!({ | ||
"name": "Barrack Obama", | ||
"email": "[email protected]", | ||
}), | ||
), | ||
( | ||
"name and url", | ||
json!({ | ||
"name": "Barrack Obama", | ||
"url": "https://potus.example.com", | ||
}), | ||
), | ||
] { | ||
let maintainer: Maintainer = serde_json::from_value(json.clone()).unwrap(); | ||
assert_eq!( | ||
json.get("name").unwrap().as_str().unwrap(), | ||
maintainer.name().to_string(), | ||
"{name}", | ||
); | ||
match json.get("email") { | ||
None => assert!(maintainer.email().is_none()), | ||
Some(email) => assert_eq!(email.as_str().unwrap(), maintainer.email().unwrap()), | ||
} | ||
match json.get("url") { | ||
None => assert!(maintainer.url().is_none()), | ||
Some(url) => assert_eq!(url.as_str().unwrap(), maintainer.url().unwrap()), | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_extension() { | ||
for (name, json) in [ | ||
( | ||
"all fields", | ||
json!({ | ||
"control": "pair.control", | ||
"abstract": "We have assumed control", | ||
"tle": true, | ||
"sql": "pair.sql", | ||
"doc": "doc/pair.md", | ||
}), | ||
), | ||
( | ||
"minimal", | ||
json!({ | ||
"control": "pair.control", | ||
"sql": "pair.sql", | ||
}), | ||
), | ||
( | ||
"false tle", | ||
json!({ | ||
"control": "pair.control", | ||
"tle": false, | ||
"sql": "pair.sql", | ||
}), | ||
), | ||
] { | ||
let extension: Extension = serde_json::from_value(json.clone()).unwrap(); | ||
assert_eq!( | ||
json.get("control").unwrap().as_str().unwrap(), | ||
extension.control().to_string(), | ||
"{name} control", | ||
); | ||
assert_eq!( | ||
json.get("sql").unwrap().as_str().unwrap(), | ||
extension.sql().to_string(), | ||
"{name} sql", | ||
); | ||
let tle = match json.get("tle") { | ||
None => false, | ||
Some(tle) => tle.as_bool().unwrap(), | ||
}; | ||
assert_eq!(tle, extension.tle()); | ||
match json.get("abstract") { | ||
None => assert!(extension.abs_tract().is_none()), | ||
Some(abs) => assert_eq!(abs.as_str().unwrap(), extension.abs_tract().unwrap()), | ||
} | ||
match json.get("doc") { | ||
None => assert!(extension.doc().is_none()), | ||
Some(doc) => assert_eq!(doc.as_str().unwrap(), extension.doc().unwrap()), | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_module_type() { | ||
for (name, mod_type) in [ | ||
("extension", ModuleType::Extension), | ||
("hook", ModuleType::Hook), | ||
("bgw", ModuleType::Bgw), | ||
] { | ||
let mt: ModuleType = serde_json::from_value(json!(name)).unwrap(); | ||
assert_eq!(mod_type, mt); | ||
assert_eq!(name, mt.to_string()) | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_preload() { | ||
for (name, preload) in [("server", Preload::Server), ("session", Preload::Session)] { | ||
let pre: Preload = serde_json::from_value(json!(name)).unwrap(); | ||
assert_eq!(preload, pre); | ||
assert_eq!(name, pre.to_string()) | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_module() { | ||
for (name, json) in [ | ||
( | ||
"all fields", | ||
json!({ | ||
"type": "hook", | ||
"lib": "lib/my_hook", | ||
"doc": "doc/my_hook.md", | ||
"preload": "session", | ||
"abstract": "My hook" | ||
}), | ||
), | ||
( | ||
"minimal", | ||
json!({ | ||
"type": "extension", | ||
"lib": "lib/my_hook", | ||
}), | ||
), | ||
] { | ||
let module: Module = serde_json::from_value(json.clone()).unwrap(); | ||
assert_eq!( | ||
json.get("type").unwrap().as_str().unwrap(), | ||
module.kind().to_string(), | ||
"{name} type", | ||
); | ||
assert_eq!( | ||
json.get("lib").unwrap().as_str().unwrap(), | ||
module.lib().to_string(), | ||
"{name} lib", | ||
); | ||
match json.get("preload") { | ||
None => assert!(module.preload().is_none()), | ||
Some(pre) => assert_eq!(pre.as_str().unwrap(), module.preload().unwrap().to_string()), | ||
} | ||
match json.get("abstract") { | ||
None => assert!(module.abs_tract().is_none()), | ||
Some(abs) => assert_eq!(abs.as_str().unwrap(), module.abs_tract().unwrap()), | ||
} | ||
match json.get("doc") { | ||
None => assert!(module.doc().is_none()), | ||
Some(doc) => assert_eq!(doc.as_str().unwrap(), module.doc().unwrap()), | ||
} | ||
} | ||
} |