diff mbox series

[2/2] main: De-Jenkinsify run_test()

Message ID 20190226042014.10707-2-andrew.donnellan@au1.ibm.com
State Accepted
Headers show
Series [1/2] main: Split run_tests() into loop and helper | expand

Commit Message

Andrew Donnellan Feb. 26, 2019, 4:20 a.m. UTC
Make run_test() generic on the CIBackend trait rather than Jenkins
specific.

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---
 src/main.rs | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/src/main.rs b/src/main.rs
index 45f994179dbf..aabf4a0d1ca8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -103,44 +103,44 @@  struct Args {
 }
 
 fn run_test(
-    jenkins: &JenkinsBackend,
+    backend: &CIBackend,
     project: &Project,
     tag: &str,
     branch_name: &str,
     job: &Job,
 ) -> TestResult {
-    let mut jenkins_params = Vec::<(&str, &str)>::new();
+    let mut params = Vec::<(&str, &str)>::new();
     for (param_name, param_value) in &job.parameters {
         // TODO(ajd): do this more neatly
         debug!("Param name {}, value {}", &param_name, &param_value);
-        jenkins_params.push((param_name, param_value));
+        params.push((param_name, param_value));
     }
-    jenkins_params.push((&job.remote, &project.remote_uri));
-    jenkins_params.push((&job.branch, tag));
+    params.push((&job.remote, &project.remote_uri));
+    params.push((&job.branch, tag));
 
     info!("Starting job: {}", &job.title);
-    let res = jenkins
-        .start_test(&job.job, jenkins_params)
-        .unwrap_or_else(|err| panic!("Starting Jenkins test failed: {}", err));
+    let res = backend
+        .start_test(&job.job, params)
+        .unwrap_or_else(|err| panic!("Starting test failed: {}", err));
     debug!("{:?}", &res);
     let build_handle_real;
     loop {
-        let build_handle = jenkins.get_build_handle(&res);
+        let build_handle = backend.get_build_handle(&res);
         if let Ok(handle) = build_handle {
             build_handle_real = handle;
             break;
         } // TODO: Handle error
     }
     debug!("Build URL: {}", build_handle_real);
-    jenkins.wait_build(&build_handle_real).unwrap(); // TODO: Error correctly
-    let mut test_result = jenkins.get_build_result(&build_handle_real).unwrap();
-    info!("Jenkins job for {}/{} complete.", branch_name, job.title);
+    backend.wait_build(&build_handle_real).unwrap(); // TODO: Error correctly
+    let mut test_result = backend.get_build_result(&build_handle_real).unwrap();
+    info!("Test job for {}/{} complete.", branch_name, job.title);
     if test_result == TestState::Fail && job.warn_on_fail {
         test_result = TestState::Warning;
     }
 
     TestResult {
-        description: match jenkins.get_description(&build_handle_real, &job.parameters) {
+        description: match backend.get_description(&build_handle_real, &job.parameters) {
             Some(description) => Some(description),
             None => Some(
                 format!("Test {} on branch {}", job.title, branch_name.to_string()).to_string(),
@@ -148,7 +148,7 @@  fn run_test(
         },
         state: test_result,
         context: Some(job.title.replace("/", "_")),
-        target_url: Some(jenkins.get_results_url(&build_handle_real, &job.parameters)),
+        target_url: Some(backend.get_results_url(&build_handle_real, &job.parameters)),
     }
 }