[jenkinscat-docs] master: Added new test: test_config.clj. (0a2a540)

immanetize at fedoraproject.org immanetize at fedoraproject.org
Fri Feb 6 07:39:55 UTC 2015


Repository : http://git.fedorahosted.org/cgit/jenkinscat-docs.git

On branch  : master

>---------------------------------------------------------------

commit 0a2a5403c64508e378003c10b0d06be76ebf39af
Author: Pavel Tisnovsky <ptisnovs at redhat.com>
Date:   Mon Dec 1 11:18:10 2014 +0100

    Added new test: test_config.clj.


>---------------------------------------------------------------

 ChangeLog                       |    5 +
 test/jenkinscat/test_config.clj |  261 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 266 insertions(+), 0 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9bbb9e3..c064481 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2014-12-01  Pavel Tisnovsky  <ptisnovs at redhat.com>
 
+	* test/jenkinscat/test_config.clj:
+	Added new test: test_config.clj.
+
+2014-12-01  Pavel Tisnovsky  <ptisnovs at redhat.com>
+
 	* src/jenkinscat/config.clj:
 	Updated, new configuration options added.
 
diff --git a/test/jenkinscat/test_config.clj b/test/jenkinscat/test_config.clj
new file mode 100644
index 0000000..96e5ecd
--- /dev/null
+++ b/test/jenkinscat/test_config.clj
@@ -0,0 +1,261 @@
+;;; Copyright (c) 2014  Pavel Tisnovsky, Red Hat
+;;; All rights reserved.
+;;;
+;;; Redistribution and use in source and binary forms, with or without
+;;; modification, are permitted provided that the following conditions are met:
+;;;     * Redistributions of source code must retain the above copyright
+;;;       notice, this list of conditions and the following disclaimer.
+;;;     * Redistributions in binary form must reproduce the above copyright
+;;;       notice, this list of conditions and the following disclaimer in the
+;;;       documentation and/or other materials provided with the distribution.
+;;;     * Neither the name of the Red Hat nor the
+;;;       names of its contributors may be used to endorse or promote products
+;;;       derived from this software without specific prior written permission.
+;;;
+;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+;;; ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+;;; DISCLAIMED. IN NO EVENT SHALL Pavel Tisnovsky BE LIABLE FOR ANY
+;;; DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+;;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+;;; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+;;; ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+
+; Tests for defs and functions defined in the following namespace: jenkinscat.config
+(ns jenkinscat.test-config
+    (:require [clojure.test :refer :all]
+              [clojure.java.io]
+              [jenkinscat.config :refer :all]))
+
+
+
+;
+; Common functions used by tests
+;
+
+(defn get-hostname
+    "Hostname of this computer"
+    []
+    ; read the real hostname 
+    (.getHostName (java.net.InetAddress/getLocalHost)))
+
+(defn proper-jobs-href-prefix?
+    "Returns true if jobs-href-prefix starts with 'http://' or 'https://'."
+    []
+    ; the URL should start with 'http://' or 'https://'
+    (or (.startsWith jobs-href-prefix "http://")
+        (.startsWith jobs-href-prefix "https://")))
+
+(defn proper-json-url-prefix?
+    "Returns true if json-url starts with 'http://' or 'https://'."
+    []
+    ; the URL should start with 'http://' or 'https://'
+    (or (.startsWith json-url "http://")
+        (.startsWith json-url "https://")))
+
+(defn proper-test-results-dir-prefix?
+    "Returns true if test-results-url-prefix starts with 'http://' or 'https://'."
+    []
+    ; the URL should start with 'http://' or 'https://'
+    (or (.startsWith test-results-url-prefix "http://")
+        (.startsWith test-results-url-prefix "https://")))
+
+(defn proper-url?
+    "Check if the given URL is properly formed."
+    [url]
+    (try
+        ; try to constructs new URL and check if any exception will occurs
+        ; (MalformedException etc. etc.)
+        (new java.net.URL url)
+        ; we are here -> URL is correct
+        true
+        (catch Exception e
+            ; we are here -> there's malformed URL or other problems
+            ; (but it's still test failure)
+            nil)))
+
+
+
+;
+; Tests for the (def hostname)
+;
+
+(deftest test-hostname-def-existence
+    "Check that the jenkinscat.config/hostname definition exists."
+    (testing "if the hostname def exists"
+        ; check if variable exists and it's bounded
+        (is (bound? (find-var 'jenkinscat.config/hostname)))))
+
+(deftest test-hostname-def-type
+    "Check that the jenkinscat.config/hostname has the correct type."
+    (testing "the hostname def type"
+        ; check if variable is of type java.lang.String
+        ; because Clojure strings are of this type
+        (is (= (type hostname) java.lang.String))))
+
+(deftest test-hostname-def-value
+    "Check that the jenkinscat.config/hostname has the correct value."
+    (testing "the hostname def value"
+        ; hostname can't be empty
+        (is (not (empty hostname)))
+        ; hostname must be the same as host computer hostname
+        (is (= hostname (get-hostname)))))
+
+
+
+;
+; Tests for the (def jobs-dir-prefix)
+;
+
+(deftest test-jobs-dir-prefix-existence
+    "Check that the jenkinscat.config/jobs-dir-prefix definition exists."
+    (testing "if the jobs-dir-prefix def exists"
+        ; check if variable exists and it's bounded
+        (is (bound? (find-var 'jenkinscat.config/jobs-dir-prefix)))))
+
+(deftest test-jobs-dir-prefix-type
+    "Check that the jenkinscat.config/jobs-dir-prefix has the correct type."
+    (testing "the jobs-dir-prefix def type"
+        ; check if variable is of type java.lang.String
+        ; because Clojure strings are of this type
+        (is (= (type jobs-dir-prefix) java.lang.String))))
+
+(deftest test-jobs-dir-prefix-value
+    "Check that the jenkinscat.config/jobs-dir-prefix has the correct value."
+    (testing "the jobs-dir-prefix def value"
+        ; value can't be empty
+        (is (not (empty jobs-dir-prefix)))
+        (is (.startsWith jobs-dir-prefix "/"))
+        (is (.endsWith jobs-dir-prefix "/"))
+        ; jobs-dir-prefix should be proper directory name
+        (is (.isDirectory (clojure.java.io/file jobs-dir-prefix )))))
+
+
+
+;
+; Tests for the (def jobs-href-prefix)
+;
+
+(deftest test-jobs-href-prefix-existence
+    "Check that the jenkinscat.config/jobs-href-prefix definition exists."
+    (testing "if the jobs-href-prefix def exists"
+        ; check if variable exists and it's bounded
+        (is (bound? (find-var 'jenkinscat.config/jobs-href-prefix)))))
+
+(deftest test-jobs-href-prefix-type
+    "Check that the jenkinscat.config/jobs-href-prefix has the correct type."
+    (testing "the jobs-href-prefix def type"
+        ; check if variable is of type java.lang.String
+        ; because Clojure strings are of this type
+        (is (= (type jobs-href-prefix) java.lang.String))))
+
+(deftest test-jobs-href-prefix-value
+    "Check that the jenkinscat.config/jobs-href-prefix has the correct value."
+    (testing "the jobs-href-prefix def value"
+        ; value can't be empty
+        (is (not (empty jobs-href-prefix)))
+        (is (proper-jobs-href-prefix?))
+        (is (.endsWith jobs-href-prefix "/"))))
+
+(deftest test-jobs-href-prefix-url
+    "Check that the jenkinscat.config/jobs-href-prefix is the proper URL."
+    (testing "the jobs-href-prefix def URL"
+        (is (proper-url? jobs-href-prefix))))
+
+
+
+;
+; Tests for the (def json-url)
+;
+
+(deftest test-json-url-existence
+    "Check that the jenkinscat.config/json-url definition exists."
+    (testing "if the json-url def exists"
+        ; check if variable exists and it's bounded
+        (is (bound? (find-var 'jenkinscat.config/json-url)))))
+
+(deftest test-json-url-type
+    "Check that the jenkinscat.config/json-url has the correct type."
+    (testing "the json-url def type"
+        ; check if variable is of type java.lang.String
+        ; because Clojure strings are of this type
+        (is (= (type json-url) java.lang.String))))
+
+(deftest test-json-url-value
+    "Check that the jenkinscat.config/json-url has the correct value."
+    (testing "the json-url def value"
+        ; value can't be empty
+        (is (not (empty json-url)))
+        (is (proper-json-url-prefix?))
+        (is (.endsWith json-url "/"))))
+
+(deftest test-json-url-url
+    "Check that the jenkinscat.config/json-url is the proper URL."
+    (testing "the jobs-href-prefix def URL"
+        (is (proper-url? json-url))))
+
+
+
+;
+; Tests for the (def test-results-url-prefix)
+;
+
+(deftest test-test-results-url-prefix-existence
+    "Check that the jenkinscat.config/test-results-url-prefix definition exists."
+    (testing "if the test-results-url-prefix def exists"
+        ; check if variable exists and it's bounded
+        (is (bound? (find-var 'jenkinscat.config/test-results-url-prefix)))))
+
+(deftest test-test-results-url-prefix-type
+    "Check that the jenkinscat.config/test-results-url-prefix has the correct type."
+    (testing "the test-results-url-prefix def type"
+        ; check if variable is of type java.lang.String
+        ; because Clojure strings are of this type
+        (is (= (type test-results-url-prefix) java.lang.String))))
+
+(deftest test-test-results-url-prefix-value
+    "Check that the jenkinscat.config/test-results-url-prefix has the correct value."
+    (testing "the test-results-url-prefix def value"
+        ; value can't be empty
+        (is (not (empty test-results-url-prefix)))
+        (is (proper-test-results-dir-prefix?))
+        (is (.endsWith test-results-url-prefix "/"))))
+
+(deftest test-test-results-url-prefix-url
+    "Check that the jenkinscat.config/test-results-url-prefix is the proper URL."
+    (testing "the test-results-url-prefix def URL"
+        (is (proper-url? test-results-url-prefix))))
+
+
+
+;
+; Tests for the (def test-results-prefix)
+;
+
+(deftest test-test-results-prefix-existence
+    "Check that the jenkinscat.config/test-results-prefix definition exists."
+    (testing "if the test-results-prefix def exists"
+        ; check if variable exists and it's bounded
+        (is (bound? (find-var 'jenkinscat.config/test-results-prefix)))))
+
+(deftest test-test-results-prefix-type
+    "Check that the jenkinscat.config/test-results-prefix has the correct type."
+    (testing "the test-results-prefix def type"
+        ; check if variable is of type java.lang.String
+        ; because Clojure strings are of this type
+        (is (= (type test-results-prefix) java.lang.String))))
+
+(deftest test-test-results-prefix-value
+    "Check that the jenkinscat.config/test-results-prefix has the correct value."
+    (testing "the test-results-prefix def value"
+        ; value can't be empty
+        (is (not (empty test-results-prefix)))
+        (is (.startsWith test-results-prefix "/"))
+        (is (.endsWith test-results-prefix "/"))
+        ; test-results-prefix should be proper directory name
+        (is (.isDirectory (clojure.java.io/file test-results-prefix )))))
+



More information about the docs-commits mailing list