Repository : http://git.fedorahosted.org/cgit/jenkinscat-docs.git
On branch : master
>---------------------------------------------------------------
commit e7b7bb53dd1256a26b6e926563d5f692f3f5a21b
Author: Pavel Tisnovsky <ptisnovs(a)redhat.com>
Date: Tue Dec 2 11:30:32 2014 +0100
Added new test: test_exec.clj.
>---------------------------------------------------------------
ChangeLog | 5 +
test/jenkinscat/test_exec.clj | 277 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 282 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c064481..cf58944 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-12-02 Pavel Tisnovsky <ptisnovs(a)redhat.com>
+
+ * test/jenkinscat/test_exec.clj:
+ Added new test: test_exec.clj.
+
2014-12-01 Pavel Tisnovsky <ptisnovs(a)redhat.com>
* test/jenkinscat/test_config.clj:
diff --git a/test/jenkinscat/test_exec.clj b/test/jenkinscat/test_exec.clj
new file mode 100644
index 0000000..5ddcfcb
--- /dev/null
+++ b/test/jenkinscat/test_exec.clj
@@ -0,0 +1,277 @@
+;;;
+;;; Jenkinscat HTTP server that handles all requests send from clients/browsers.
+;;;
+;;; 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.exec
+(ns jenkinscat.test-exec
+ (:require [clojure.test :refer :all]
+ [clojure.java.io]
+ [jenkinscat.exec :refer :all]))
+
+
+
+;
+; Common functions used by tests
+;
+
+(defn callable?
+ "Test if given function-name is bound to the real function."
+ [function-name]
+ (clojure.test/function? function-name))
+
+(defn call-exec-without-args
+ "Check if exec could/could not be called without arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec without args
+ (exec)
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-empty-arg
+ "Check if exec could/could not be called with one empty argument."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with empty
+ (exec "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-two-empty-args
+ "Check if exec could/could not be called with two empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with two empty arguments
+ (exec "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-three-empty-args
+ "Check if exec could/could not be called with three empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with three empty arguments
+ (exec "" "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-four-empty-args
+ "Check if exec could/could not be called with four empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with four empty arguments
+ (exec "" "" "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-five-empty-args
+ "Check if exec could/could not be called with five empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with five empty arguments
+ (exec "" "" "" "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-six-empty-args
+ "Check if exec could/could not be called with six empty arguments."
+ []
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with six empty arguments
+ (exec "" "" "" "" "" "")
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-improper-command
+ "Check if exec could/could not be called with improper command."
+ [command]
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with improper command
+ (exec command)
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+(defn call-exec-with-improper-command-arg
+ "Check if exec could/could not be called with improper command."
+ [command arg]
+ ; we assume that exception would be thrown, so we catch it
+ ; and return true if and only if exception is caught
+ (try
+ ; run exec with improper command
+ (exec command arg)
+ ; we are here? it's an error
+ nil
+ (catch Exception e
+ ; (any) exception is expected in this case
+ true)))
+
+
+
+;
+; Tests for the (defn exec)
+;
+
+(deftest test-exec-existence
+ "Check that the jenkinscat.exec/exec definition exists."
+ (testing "if the jenkinscat.exec/exec def exists"
+ (is (callable? 'jenkinscat.exec/exec))))
+
+(deftest test-exec-function-without-args
+ "Test exec function behaviour"
+ (testing "exec function behaviour"
+ ; call (exec)
+ (is (call-exec-without-args))))
+
+(deftest test-exec-function-with-empty-arg
+ "Test exec function behaviour"
+ (testing "exec function behaviour"
+ ; call (exec "")
+ (is (call-exec-with-empty-arg))))
+
+(deftest test-exec-function-with-empty-args
+ "Test exec function behaviour"
+ (testing "exec function behaviour"
+ ; call (exec "" "")
+ (is (call-exec-with-two-empty-args))
+ ; call (exec "" "" "")
+ (is (call-exec-with-three-empty-args))
+ ; call (exec "" "" "" "")
+ (is (call-exec-with-four-empty-args))
+ ; call (exec "" "" "" "" "")
+ (is (call-exec-with-five-empty-args))
+ ; call (exec "" "" "" "" "" "")
+ (is (call-exec-with-six-empty-args))))
+
+(deftest test-exec-function-with-real-commands
+ "Test exec function with real commands (ls etc.)"
+ (testing "exec function behaviour"
+ ; call (exec "date")
+ (is (exec "date"))
+ ; call (exec "ls")
+ (is (exec "ls"))
+ ; call (exec "ls -1")
+ (is (exec "ls -1"))
+ ; call (exec "ls -1 -c")
+ (is (exec "ls -1 -c"))
+ ; call (exec "ls -a -1 -c")
+ (is (exec "ls -a -1 -c"))
+ ; call (exec "ls -a -1 -c -C")
+ (is (exec "ls -a -1 -c -C"))
+ ; call (exec "ls -a -1 -c -C -d")
+ (is (exec "ls -a -1 -c -C -d"))
+ ; call (exec "ls -a -1 -c -C -d -g")
+ (is (exec "ls -a -1 -c -C -d -g"))
+ ; call (exec "ls" "-1")
+ (is (exec "ls" "-1"))
+ ; call (exec "ls" "-1" "-c")
+ (is (exec "ls" "-1" "-c"))
+ ; call (exec "ls" "-a" "-1" "-c")
+ (is (exec "ls" "-a" "-1 -c"))
+ ; call (exec "ls" "-a" "-1" "-c" "-C")
+ (is (exec "ls" "-a" "-1" "-c" "-C"))
+ ; call (exec "ls" "-a" "-1" "-c" "-C" "-d")
+ (is (exec "ls" "-a" "-1" "-c" "-C" "-d"))
+ ; call (exec "ls" "-a" "-1" "-c" "-C" "-d" "-g")
+ (is (exec "ls" "-a" "-1" "-c" "-C" "-d" "-g"))))
+
+(deftest test-exec-function-with-improper-commands
+ "Test exec function with improper commands."
+ (testing "exec function behaviour"
+ ; call (exec "-")
+ (is (call-exec-with-improper-command "-"))
+ ; call (exec "---")
+ (is (call-exec-with-improper-command "---"))
+ ; call (exec "/")
+ (is (call-exec-with-improper-command "/"))
+ ; call (exec "//")
+ (is (call-exec-with-improper-command "//"))
+ ; call (exec "?")
+ (is (call-exec-with-improper-command "?"))
+ ; call (exec "??")
+ (is (call-exec-with-improper-command "??"))
+ ; call (exec "xyzzy")
+ (is (call-exec-with-improper-command "xyzzy"))))
+
+(deftest test-exec-function-with-improper-commands-arg
+ "Test exec function with improper commands."
+ (testing "exec function behaviour"
+ ; call (exec "-" "x")
+ (is (call-exec-with-improper-command-arg "-" "x"))
+ ; call (exec "---" "x")
+ (is (call-exec-with-improper-command-arg "---" "x"))
+ ; call (exec "/" "x")
+ (is (call-exec-with-improper-command-arg "/" "x"))
+ ; call (exec "//" "x")
+ (is (call-exec-with-improper-command-arg "//" "x"))
+ ; call (exec "?" "x")
+ (is (call-exec-with-improper-command-arg "?" "x"))
+ ; call (exec "??" "x")
+ (is (call-exec-with-improper-command-arg "??" "x"))
+ ; call (exec "xyzzy" "x")
+ (is (call-exec-with-improper-command-arg "xyzzy" "x"))))
+
Repository : http://git.fedorahosted.org/cgit/jenkinscat-docs.git
On branch : master
>---------------------------------------------------------------
commit 0a2a5403c64508e378003c10b0d06be76ebf39af
Author: Pavel Tisnovsky <ptisnovs(a)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(a)redhat.com>
+ * test/jenkinscat/test_config.clj:
+ Added new test: test_config.clj.
+
+2014-12-01 Pavel Tisnovsky <ptisnovs(a)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 )))))
+