From 81390cd0d3b36f732f6e6071160fb944e1f12892 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 12 Nov 2017 20:06:13 +0100 Subject: Update tests for Jenkins mock URL Now that the Jenkins API URL is getting passed in via command line and function argument, update the tests to pass it in directly. Remove the test/non-test versions of `jenkins_url` from `find_and_track_build_and_update_status()` because we can pass in the mock URL directly to the `get_jobs()` and `request_job()` functions in tests. Make the `jenkins_url` argument to `find_and_track_build_and_update_status()` not a reference so that we don't have to reset it in the function to a `to_owned()` version. --- src/jenkins.rs | 16 +++++++--------- src/main.rs | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/jenkins.rs b/src/jenkins.rs index b46f5ae..a41b11c 100644 --- a/src/jenkins.rs +++ b/src/jenkins.rs @@ -76,7 +76,7 @@ impl Job { pub fn find_and_track_build_and_update_status( commit_ref: CommitRef, - jenkins_url: &String, + jenkins_url: String, jenkins_user_id: &String, jenkins_token: &String, github_token: String, @@ -86,12 +86,6 @@ pub fn find_and_track_build_and_update_status( &jenkins_token )?; - #[cfg(not(test))] - let jenkins_url = jenkins_url.to_owned(); - - #[cfg(test)] - let jenkins_url = mockito::SERVER_URL; - let jobs = get_jobs( &jenkins_url, &jenkins_client, @@ -337,8 +331,11 @@ mod tests { "#) .create(); - let jobs = get_jobs(&test_request_client(), "changes") - .expect("Failed to request jobs"); + let jobs = get_jobs( + &mockito::SERVER_URL.to_owned(), + &test_request_client(), + "changes" + ).expect("Failed to request jobs"); assert_eq!( jobs, @@ -363,6 +360,7 @@ mod tests { .create(); let job = request_job( + &mockito::SERVER_URL.to_owned(), &test_request_client(), "http://jenkins.example.com/job/changes-branches/15" ).expect("Failed to request job"); diff --git a/src/main.rs b/src/main.rs index fdcdeeb..3f3351a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -105,7 +105,7 @@ fn main() { match jenkins::find_and_track_build_and_update_status( commit_ref, - &jenkins_url, + jenkins_url.clone(), &jenkins_user_id, &jenkins_token, github_token.clone(), -- cgit v1.2.3