[v3,2/3] settings: add basic tests
diff mbox

Message ID 20170324032827.21648-2-andrew.donnellan@au1.ibm.com
State Accepted
Delegated to: Russell Currey
Headers show

Commit Message

Andrew Donnellan March 24, 2017, 3:28 a.m. UTC
Signed-off-by: Andrew Donnellan <andrew.donnellan@au1.ibm.com>

---
v2->v3:
* add missing explanation in invalid.toml

---
 examples/tests/invalid.toml | 77 +++++++++++++++++++++++++++++++++++++++++++++
 src/settings.rs             | 22 +++++++++++++
 2 files changed, 99 insertions(+)
 create mode 100644 examples/tests/invalid.toml

Patch
diff mbox

diff --git a/examples/tests/invalid.toml b/examples/tests/invalid.toml
new file mode 100644
index 0000000..39fd2a8
--- /dev/null
+++ b/examples/tests/invalid.toml
@@ -0,0 +1,77 @@ 
+#
+# snowpatch - continuous integration for patch-based workflows
+#
+# Copyright (C) 2016 IBM Corporation
+# Authors:
+#     Russell Currey <ruscur@russell.cc>
+#     Andrew Donnellan <andrew.donnellan@au1.ibm.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; either version 2 of the License, or (at your option)
+# any later version.
+#
+# invalid.toml - configuration file that's missing mandatory fields
+#
+
+[git]
+user = "git"
+public_key = "/home/ruscur/.ssh/id_rsa.pub"
+private_key = "/home/ruscur/.ssh/id_rsa"
+
+[patchwork]
+url = "https://russell.cc/patchwork"
+port = 443 # optional
+user = "ruscur" # optional, needed for pushing results
+pass = "banana" # optional, needed for pushing results
+polling_interval = 10 # polling interval in minutes
+
+[jenkins]
+url = "https://jenkins.ozlabs.ibm.com"
+port = 443
+username = "patchwork"
+token = "33333333333333333333333333333333"
+
+[projects]
+
+    # the name of the project must be as is in patchwork
+    [projects.skiboot]
+    repository = "/home/ruscur/Documents/skiboot"
+    branches = ["master", "stable"] # branches to base from
+    test_all_branches = false
+    remote_name = "github"
+    remote_uri = "git@github.com:ruscur/skiboot.git"
+    push_results = false
+
+        [[projects.skiboot.jobs]]
+        job = "skiboot-compile-test-snowpatch"
+        remote = "GIT_REPO"
+        branch = "GIT_REF"
+
+        [[projects.skiboot.jobs]]
+        job = "skiboot-boot-test-snowpatch"
+        remote = "GIT_REPO"
+        branch = "GIT_REF"
+        artifact = "snowpatch.txt"
+
+    [projects.linuxppc-dev]
+    repository = "/home/ruscur/Documents/linux"
+    branches = ["master", "powerpc-next"]
+    # test_all_branches defaults to true
+    remote_name = "github"
+    remote_uri = "git@github.com:ruscur/linux.git"
+    push_results = false
+
+        [[projects.linuxppc-dev.jobs]]
+        # Missing mandatory field: job = "linux-build-manual"
+        remote = "GIT_REPO"
+        branch = "GIT_REF"
+        artifact = "snowpatch.txt"
+        DEFCONFIG_TO_USE = "pseries_le_defconfig"
+
+        [[projects.linuxppc-dev.jobs]]
+        job = "linux-build-manual"
+        remote = "GIT_REPO"
+        branch = "GIT_REF"
+        artifact = "snowpatch.txt"
+        DEFCONFIG_TO_USE = "ppc64le_defconfig"
diff --git a/src/settings.rs b/src/settings.rs
index e05bc98..826f792 100644
--- a/src/settings.rs
+++ b/src/settings.rs
@@ -104,3 +104,25 @@  pub fn parse(path: &str) -> Config {
         }
     }
 }
+
+#[cfg(test)]
+mod test {
+    use settings::*;
+
+    #[test]
+    #[should_panic(expected = "Couldn't open config file")]
+    fn bad_path() {
+        parse("/nonexistent/config.file");
+    }
+
+    #[test]
+    fn parse_example_openpower() {
+        parse("examples/openpower.toml");
+    }
+
+    #[test]
+    #[should_panic(expected = "Could not parse configuration file, exiting")]
+    fn parse_example_invalid() {
+        parse("examples/tests/invalid.toml");
+    }
+}