Skip to content

Commit

Permalink
Merge 0c0d93c into 02ce64d
Browse files Browse the repository at this point in the history
  • Loading branch information
krriteshgupta committed Jun 13, 2019
2 parents 02ce64d + 0c0d93c commit f665cb9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/ziggurat/init.clj
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@
{s/Keyword {:handler-fn (s/pred #(fn? %))
s/Keyword (s/pred #(fn? %))}}))

(defn validate-stream-routes [stream-routes]
(s/validate StreamRoute stream-routes))
(defn validate-stream-routes [stream-routes modes]
(when (or (empty? modes) (contains? (set modes) :stream-worker))
(s/validate StreamRoute stream-routes)))

(defn validate-modes [modes]
(let [invalid-modes (filter #(not (contains? (set (keys valid-modes-fns)) %)) modes)
Expand All @@ -160,7 +161,7 @@
([{:keys [start-fn stop-fn stream-routes actor-routes modes]}]
(try
(validate-modes modes)
(validate-stream-routes stream-routes)
(validate-stream-routes stream-routes modes)
(add-shutdown-hook stop-fn modes)
(start start-fn stream-routes actor-routes modes)
(catch clojure.lang.ExceptionInfo e
Expand Down
37 changes: 22 additions & 15 deletions test/ziggurat/init_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,33 @@

(deftest validate-stream-routes-test
(let [exception-message "Invalid stream routes"]
(testing "Validate Stream Routes should raise exception if stream routes is nil"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes nil))))
(testing "Validate Stream Routes should raise exception if stream routes is nil and stream worker is one of the modes"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes nil [:stream-worker]))))

(testing "Validate Stream Routes should raise exception if stream routes are empty"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes {}))))
(testing "Validate Stream Routes should raise exception if stream routes are empty and stream worker is one of the modes"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes {} [:stream-worker]))))

(testing "Validate Stream Routes should raise exception if stream route does not have handler-fn"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes {:default {}}))))
(testing "Validate Stream Routes should raise exception if stream route does not have handler-fn and stream worker is one of the modes"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes {:default {}} [:stream-worker]))))

(testing "Validate Stream Routes should raise exception if stream route does have nil value"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes {:default nil}))))
(testing "Validate Stream Routes should raise exception if stream route does have nil value and stream worker is one of the modes"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes {:default nil} [:stream-worker]))))

(testing "Validate Stream Routes should raise exception if stream route has nil handler-fn"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes {:default {:handler-fn nil}}))))
(testing "Validate Stream Routes should raise exception if stream route has nil handler-fn and stream worker is one of the modes"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes {:default {:handler-fn nil}} [:stream-worker]))))

(testing "Validate Stream Routes should raise exception if stream route has nil handler-fn"
(let [stream-route {:default {:handler-fn (fn [])
:channel-1 (fn [])
:channel-2 (fn [])}}]
(is (= stream-route (init/validate-stream-routes stream-route)))))))
(testing "Validate Stream Routes should raise exception if stream route has nil handler-fn and there is no mode passed"
(is (thrown? RuntimeException exception-message (init/validate-stream-routes {:default {:handler-fn nil}} nil)))))

(testing "Validate Stream Routes should return nil if stream route is empty or nil and stream worker is not one of the modes"
(is (nil? (init/validate-stream-routes nil [:api-server])))
(is (nil? (init/validate-stream-routes {} [:api-server]))))

(testing "Validate Stream Routes should raise exception if stream route has nil handler-fn"
(let [stream-route {:default {:handler-fn (fn [])
:channel-1 (fn [])
:channel-2 (fn [])}}]
(is (= stream-route (init/validate-stream-routes stream-route [:stream-worker]))))))

(deftest ziggurat-routes-serve-actor-routes-test
(testing "The routes added by actor should be served along with ziggurat-routes"
Expand Down

0 comments on commit f665cb9

Please sign in to comment.