From 13e82e9dad7f18cf7371b4aab1ade63ef651313e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 8 Nov 2017 21:11:12 +0100 Subject: jenkins.rs: Make `get_jobs` test real Instead of just calling the `get_jobs` function, make this a real test and check its return value using a mocked response, now that we have 'mockito' at our disposition. --- src/jenkins.rs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/jenkins.rs b/src/jenkins.rs index 46ccbd5..a82084e 100644 --- a/src/jenkins.rs +++ b/src/jenkins.rs @@ -124,7 +124,37 @@ mod tests { #[test] fn get_jobs_queries_jobs_from_jenkins_api() { - get_jobs("changes".to_string()); + let mock = mock("GET", "/job/changes-branches/api/json") + .with_status(200) + .with_header("content-type", "application/json;charset=utf-8") + .with_body(r#" + { + "displayName": "changes-branches", + "builds": [ + { + "_class": "hudson.model.FreeStyleBuild", + "number": 18, + "url": "http://jenkins.example.com/job/changes-branches/18/" + }, + { + "_class": "hudson.model.FreeStyleBuild", + "number": 17, + "url": "http://jenkins.example.com/job/changes-branches/17/" + } + ] + } + "#) + .create(); + + let jobs = get_jobs("changes".to_string()); + + assert_eq!( + jobs, + [ + "http://jenkins.example.com/job/changes-branches/18/", + "http://jenkins.example.com/job/changes-branches/17/" + ] + ); } #[test] -- cgit v1.2.3