From a809389b9e310274ada897eee289812fcad6c61b Mon Sep 17 00:00:00 2001 From: "deep.mistry" Date: Fri, 25 Sep 2020 13:34:06 +0530 Subject: [PATCH] Change in validation of stream and batch routes --- src/ziggurat/init.clj | 9 ++++++--- test/ziggurat/init_test.clj | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/ziggurat/init.clj b/src/ziggurat/init.clj index 47d6c831..59a4687a 100644 --- a/src/ziggurat/init.clj +++ b/src/ziggurat/init.clj @@ -184,9 +184,12 @@ (defn validate-routes [stream-routes batch-routes modes] (if (empty? modes) - (do - (s/validate StreamRoute stream-routes) - (s/validate BatchRoute batch-routes)) + (cond + (and (some? stream-routes) (some? batch-routes)) (do (s/validate StreamRoute stream-routes) + (s/validate BatchRoute batch-routes)) + (some? stream-routes) (s/validate StreamRoute stream-routes) + (some? batch-routes) (s/validate BatchRoute batch-routes) + :else (throw (IllegalArgumentException. "Either :stream-routes or :batch-routes should be present in initial args for ziggurat"))) (do (when (contains? (set modes) :stream-worker) (s/validate StreamRoute stream-routes)) diff --git a/test/ziggurat/init_test.clj b/test/ziggurat/init_test.clj index 7384403b..9798d044 100644 --- a/test/ziggurat/init_test.clj +++ b/test/ziggurat/init_test.clj @@ -155,7 +155,23 @@ :channel-1 (fn []) :channel-2 (fn [])}} batch-route {:consumer-1 {:handler-fn #()}}] - (is (= batch-route (init/validate-routes stream-route batch-route [:stream-worker :batch-worker]))))))) + (is (= batch-route (init/validate-routes stream-route batch-route [:stream-worker :batch-worker]))))) + (testing "nil modes : batch routes and stream routes not present should raise an exception" + (is (thrown? IllegalArgumentException (init/validate-routes nil nil nil)))) + (testing "nil modes : batch routes not present and stream routes are present should not throw exception" + (is (some? (init/validate-routes {:default {:handler-fn (fn [])}} nil nil)))) + (testing "nil modes : stream routes not present and batch routes are present should not throw exception" + (is (some? (init/validate-routes nil {:consumer-1 {:handler-fn (fn [])}} nil)))) + (testing "nil modes : stream routes and batch routes are present should return not throw exception" + (is (some? (init/validate-routes {:default {:handler-fn (fn [])}} {:consumer-1 {:handler-fn (fn [])}} nil)))) + (testing "with modes : stream-worker present in modes and stream routes not present should throw an exception" + (is (thrown? Exception (init/validate-routes nil nil [:api-server :stream-worker])))) + (testing "with modes : batch-worker present in modes and batch routes not present should throw an exception" + (is (thrown? Exception (init/validate-routes nil nil [:api-server :batch-worker])))) + (testing "with modes : batch-worker and stream-worker present in modes and batch routes and stream routes present should not throw an exception" + (is (some? (init/validate-routes {:default {:handler-fn (fn [])}} {:consumer-1 {:handler-fn (fn [])}} [:api-server :stream-worker :batch-worker])))) + (testing "with modes : actor routes present in modes and arguments should return nil" + (is (nil? (init/validate-routes nil nil [:api-server])))))) (deftest ziggurat-routes-serve-actor-routes-test (testing "The routes added by actor should be served along with ziggurat-routes"