Make TestState less horrible
diff mbox

Message ID 20170203062453.8960-1-andrew.donnellan@au1.ibm.com
State Accepted
Headers show

Commit Message

Andrew Donnellan Feb. 3, 2017, 6:24 a.m. UTC
Make TestState look a bit less disgusting. Implement Clone, Default,
ToJson, RustcEncodable and change the enum to all-lowercase so we can
serialise straight to JSON. (All-lowercase enum variants violates coding
style guidelines, sadly until we switch to serde there's no easy way around
that.)

Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>
---

for information only, already merged

---
 src/main.rs      |  8 ++++----
 src/patchwork.rs | 24 ++++++++++--------------
 2 files changed, 14 insertions(+), 18 deletions(-)

Patch
diff mbox

diff --git a/src/main.rs b/src/main.rs
index 0913277..9909243 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -134,7 +134,7 @@  fn run_tests(settings: &Config, client: Arc<Client>, project: &Project, tag: &st
         info!("Jenkins job for {}/{} complete.", branch_name, job_name);
         results.push(TestResult {
             test_name: format!("{}/{}", branch_name.to_string(), job_name.to_string()),
-            state: TestState::SUCCESS.string(), // TODO: get this from Jenkins
+            state: TestState::success,
             url: None, // TODO: link to Jenkins job log
             summary: Some("TODO: get this summary from Jenkins".to_string()),
         });
@@ -197,7 +197,7 @@  fn test_patch(settings: &Config, client: &Arc<Client>, project: &Project, path:
                 successfully_applied = true;
                 results.push(TestResult {
                     test_name: "apply_patch".to_string(),
-                    state: TestState::SUCCESS.string(),
+                    state: TestState::success,
                     url: None,
                     summary: Some(format!("Successfully applied to branch {}", branch_name)),
                 });
@@ -206,7 +206,7 @@  fn test_patch(settings: &Config, client: &Arc<Client>, project: &Project, path:
                 // It didn't apply.  No need to bother testing.
                 results.push(TestResult {
                     test_name: "apply_patch".to_string(),
-                    state: TestState::WARNING.string(),
+                    state: TestState::warning,
                     url: None,
                     summary: Some(format!("Failed to apply to branch {}", branch_name)),
                 });
@@ -232,7 +232,7 @@  fn test_patch(settings: &Config, client: &Arc<Client>, project: &Project, path:
     if !successfully_applied {
         results.push(TestResult {
             test_name: "apply_patch".to_string(),
-            state: TestState::FAILURE.string(),
+            state: TestState::failure,
             url: None,
             summary: Some("Failed to apply to any branch".to_string()),
         });
diff --git a/src/patchwork.rs b/src/patchwork.rs
index a6f761a..b9308c3 100644
--- a/src/patchwork.rs
+++ b/src/patchwork.rs
@@ -81,22 +81,18 @@  pub struct SeriesList {
 }
 
 // TODO: remove this when we have Jenkins result handling
-#[allow(dead_code)]
+#[allow(warnings)] // for not being camelcase because encoding
+#[derive(RustcEncodable, Clone)]
 pub enum TestState {
-    PENDING,
-    SUCCESS,
-    WARNING,
-    FAILURE
+    pending,
+    success,
+    warning,
+    failure,
 }
 
-impl TestState {
-    pub fn string(&self) -> String {
-        match *self {
-            TestState::PENDING => "pending".to_string(),
-            TestState::SUCCESS => "success".to_string(),
-            TestState::WARNING => "warning".to_string(),
-            TestState::FAILURE => "failure".to_string(),
-        }
+impl Default for TestState {
+    fn default() -> TestState {
+        TestState::pending
     }
 }
 
@@ -104,7 +100,7 @@  impl TestState {
 #[derive(RustcEncodable)]
 pub struct TestResult {
     pub test_name: String,
-    pub state: String,
+    pub state: TestState,
     pub url: Option<String>,
     pub summary: Option<String>
 }