Skip to content

Commit

Permalink
add some test
Browse files Browse the repository at this point in the history
  • Loading branch information
minhtuannguyen committed Jul 24, 2016
1 parent ebe257f commit 40e7ec5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/leiningen/remote_test_refresh.clj
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@
(recur)))

(defn valid-port? [port]
(and (not= :empty port) (not= :invalid port) (> port 1023)))
(and (not= :empty port)
(not= :invalid port)
(> port 1023)))

(defn has-port? [parameters]
(contains? parameters :forwarding-port))
Expand All @@ -86,13 +88,13 @@
(with-open [rdr (io/reader output)]
(doseq [line (line-seq rdr)] (m/info line)))))

(defn notify [shell notify-cmd msg]
(defn notify [shell log notify-cmd msg]
(let [should-notify? (not (empty? notify-cmd))]
(when should-notify?
(try
(apply shell (create-notify-command notify-cmd msg))
(catch Exception e (m/info "* Could not notify: " (.getMessage e))))))
(m/info "*" msg))
(log "*" msg))

(defn run-command-and-forward-port [session parameters]
(let [{port :forwarding-port cmd :command} parameters
Expand All @@ -111,7 +113,7 @@

(defn notify-log [console parameters]
(async/go-loop [{msg :msg} (async/<! console)]
(notify sh/sh (:notify-command parameters) msg)
(notify sh/sh m/info (:notify-command parameters) msg)
(recur (async/<! console))))

(defn log-to [console msg]
Expand Down
29 changes: 28 additions & 1 deletion test/leiningen/remote_test_refresh_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,31 @@
(is (= ["do notify" "msg"]
(rt/create-notify-command "do notify" "msg")))
(is (= ["do" "notify" "msg"]
(rt/create-notify-command ["do" "notify"] "msg"))))
(rt/create-notify-command ["do" "notify"] "msg"))))

(deftest ^:unit test-has-port?
(is (false? (rt/has-port? {:foo :bar})))
(is (false? (rt/has-port? {})))
(is (false? (rt/has-port? nil)))
(is (true? (rt/has-port? {:forwarding-port 20}))))

(deftest ^:unit test-notify
(let [state-shell (atom [])
state-log (atom [])
log (fn [& args] (reset! state-log args))
shell (fn [& args] (reset! state-shell args))
notify-cmd ["do" "something"]
msg "msg"
_ (rt/notify shell log notify-cmd msg)]
(is (= ["do" "something" "msg"] @state-shell))
(is (= ["*" "msg"] @state-log)))

(let [state-shell (atom [])
shell (fn [& args] (reset! state-shell args))
state-log (atom [])
log (fn [& args] (reset! state-log args))
notify-cmd []
msg "msg"
_ (rt/notify shell log notify-cmd msg)]
(is (= [] @state-shell))
(is (= ["*" "msg"] @state-log))))

0 comments on commit 40e7ec5

Please sign in to comment.