 (ns meerkat.services_test
   (:require [clojure.test :refer :all]
-            [meerkat.services :as services])
+            [meerkat.services :as s])
   (:import [meerkat.services Service]))
 
 (defrecord TestService [name dependencies configuration]
   Service
   (configure [this new-configuration]
-    (meerkat.services/configure-service this configuration new-configuration))
+    (s/configure-service this configuration new-configuration))
   (start [_] "start service" (println "start"))
   (stop [_] "stop service" (println "stop")))
 

            dao-service
            event-service
            db-service]]
      (is (thrown? Throwable (services/sort-services declared-services))))))

(defrecord TestService1 [name dependencies configuration started]
  Service
  (configure [this new-configuration]
    (meerkat.services/configure-service this configuration new-configuration))
  (start [_] "start service" (reset! started true))
  (stop [_] "stop service" (reset! started false)))

(defrecord TestService2 [name dependencies configuration started test-service1]
  Service
  (configure [this new-configuration]
    (meerkat.services/configure-service this configuration new-configuration))
  (start [_] "start service" (reset! started true))
  (stop [_] "stop service" (reset! started false)))

(defrecord TestService3 [name dependencies configuration started test-service1 test-service2]
  Service
  (configure [this new-configuration]
    (meerkat.services/configure-service this configuration new-configuration))
  (start [_] "start service" (reset! started true))
  (stop [_] "stop service" (reset! started false)))


          test-service1 (->TestService1 :test-service1 [] (atom {}) (atom false))
          test-service2 (->TestService2 :test-service2 [:test-service1] (atom {}) (atom false) nil)
          test-service3 (->TestService3 :test-service3 [:test-service1 :test-service2] (atom {}) (atom false) nil nil)
          services-with-dependencies (s/inject-dependencies (s/sort-services [test-service1 test-service2 test-service3]))
          test-service2-with-dependencies (nth services-with-dependencies 1)
          test-service3-with-dependencies (nth services-with-dependencies 2)]
      (is (= :test-service1 (-> test-service2-with-dependencies :test-service1 :name)))
