From patchwork Fri Mar 24 03:04:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Donnellan X-Patchwork-Id: 743039 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vq7Zh6DMvz9s7J for ; Fri, 24 Mar 2017 14:05:16 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vq7Zh5MF9zDqZQ for ; Fri, 24 Mar 2017 14:05:16 +1100 (AEDT) X-Original-To: snowpatch@lists.ozlabs.org Delivered-To: snowpatch@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vq7Zd11QmzDq7d for ; Fri, 24 Mar 2017 14:05:12 +1100 (AEDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v2O347cf108797 for ; Thu, 23 Mar 2017 23:05:10 -0400 Received: from e23smtp02.au.ibm.com (e23smtp02.au.ibm.com [202.81.31.144]) by mx0b-001b2d01.pphosted.com with ESMTP id 29cf06bd31-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 23 Mar 2017 23:05:10 -0400 Received: from localhost by e23smtp02.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 24 Mar 2017 13:05:07 +1000 Received: from d23relay09.au.ibm.com (202.81.31.228) by e23smtp02.au.ibm.com (202.81.31.208) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 24 Mar 2017 13:05:05 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v2O34ve147972466 for ; Fri, 24 Mar 2017 14:05:05 +1100 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v2O34WYP029603 for ; Fri, 24 Mar 2017 14:04:32 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v2O34W1r029131 for ; Fri, 24 Mar 2017 14:04:32 +1100 Received: from ajd.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 96F1BA024D for ; Fri, 24 Mar 2017 14:04:08 +1100 (AEDT) From: Andrew Donnellan To: snowpatch@lists.ozlabs.org Date: Fri, 24 Mar 2017 14:04:02 +1100 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170324030402.16619-1-andrew.donnellan@au1.ibm.com> References: <20170324030402.16619-1-andrew.donnellan@au1.ibm.com> X-TM-AS-MML: disable x-cbid: 17032403-0004-0000-0000-000001F0A11B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17032403-0005-0000-0000-000009E2C4E8 Message-Id: <20170324030402.16619-2-andrew.donnellan@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-24_02:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=1 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703240026 Subject: [snowpatch] [PATCH v2 2/2] settings: add basic tests X-BeenThere: snowpatch@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Continuous Integration for patch-based workflows List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: snowpatch-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "snowpatch" Signed-off-by: Andrew Donnellan --- v1->v2: * add invalid.toml test file --- examples/tests/invalid.toml | 77 +++++++++++++++++++++++++++++++++++++++++++++ src/settings.rs | 22 +++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 examples/tests/invalid.toml diff --git a/examples/tests/invalid.toml b/examples/tests/invalid.toml new file mode 100644 index 0000000..b719c9f --- /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 +# Andrew Donnellan +# +# 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 +# + +[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"); + } +}