Skip to content
This repository has been archived by the owner on Apr 30, 2021. It is now read-only.

Commit

Permalink
some trivial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Apr 28, 2015
1 parent b6ce9ea commit f3122c6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/org/zalando/stups/even/job.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
[ssh db {:keys [id hostname remote_host username] :as req}]
(let [remaining-count (:count (first (sql/count-remaining-granted-access-requests {:hostname hostname :id id} {:connection db})))
options (get-revoke-ssh-access-options remote_host username remaining-count)]
(execute-ssh hostname (apply str options) ssh)))
(execute-ssh hostname (clojure.string/join " " options) ssh)))

(defn revoke-expired-access-request
"Revoke a single expired access request"
Expand All @@ -37,7 +37,7 @@
(log/info msg))
(let [msg (str "SSH command failed: " (or (:err result) (:out result)))]
(sql/update-access-request-status req "GRANTED" msg "job" db)
(log/error {} msg)))))
(log/warn msg)))))

(defn revoke-expired-access-requests
"Revoke all expired access requests"
Expand Down
17 changes: 17 additions & 0 deletions test/org/zalando/stups/even/job_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
(deftest test-get-revoke-ssh-options
(is (= ["revoke-ssh-access" "myuser" "--remote-host" "myremote" "--keep-local"] (get-revoke-ssh-access-options "myremote" "myuser" 1))))

(deftest test-acquire-lock
(with-redefs [sql/acquire-lock (constantly [{:l_id 123}])]
(is (= {:id 123} (acquire-lock {})))))

(deftest test-acquire-lock-fail
(with-redefs [sql/acquire-lock (fn [_ _] (throw (Exception. "duplicate key value violates unique constraint")))]
(is (nil? (acquire-lock {})))))

(deftest test-revoke-access-requests
(with-redefs [sql/get-expired-access-requests (constantly [{}])
sql/update-access-request! (constantly 1)
Expand All @@ -17,6 +25,15 @@
(revoke-expired-access-requests {} {})))


(deftest test-revoke-access-requests-ssh-failure
(with-redefs [sql/get-expired-access-requests (constantly [{}])
sql/update-access-request! (constantly 1)
sql/count-remaining-granted-access-requests (constantly [{:count 0}])
ssh/execute-ssh (constantly {:exit 1})]

(revoke-expired-access-requests {} {})))





Expand Down
8 changes: 8 additions & 0 deletions test/org/zalando/stups/even/sql_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns org.zalando.stups.even.sql-test
(:require [clojure.test :refer :all]
[org.zalando.stups.even.job :refer :all]
[org.zalando.stups.even.sql :as sql]
[org.zalando.stups.even.ssh :as ssh]))

(deftest test-from-sql
(is (= {:foo_bar "hello"} (sql/from-sql {:tp_foo_bar "hello"}))))

0 comments on commit f3122c6

Please sign in to comment.