Created
June 4, 2016 20:05
-
-
Save claj/b2f98ba0009d72607e5126b2478261e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns example.service-test | |
"Assuming we have a example.service returning a component system (with using... etc) | |
starts this, stops it etc." | |
(:require | |
[clojure.test :refer :all] | |
[example.service :refer :all] | |
[com.stuartsierra.component :as component]) ) | |
(defn first-free-port | |
"Returns first free ephemeral port | |
from https://github.com/zeromq/cljzmq/blob/master/src/zeromq/zmq.clj" | |
[] | |
(with-open [ss (java.net.ServerSocket. 0)] | |
(.getLocalPort ss))) | |
(defn- generate-unique-test-config | |
"Generates a non-colliding system configuration. | |
When this fail, it's usually because new options | |
are added in the project.clj" | |
[] | |
{:datomic-uri (str "datomic:mem://test" (gensym)) | |
:pedestal-port (str (first-free-port)) | |
:pedestal-ssl-port (str (first-free-port)) | |
:admin-ssl-port (str (first-free-port)) | |
:site-hostname "testing.com" | |
}) | |
(deftest standard-sys-up-and-down | |
(testing "that we can start a system on random free ports" | |
(let [test-config (generate-unique-test-config) | |
instance (standard-sys test-config) | |
started1 (component/start instance)] | |
(is (conn? (get-in started1 [:datomic-conn :conn]))) | |
(testing "to stop this system without crashes" | |
(let [stopped-sys (component/stop started1)] | |
(is stopped-sys))) | |
(testing "if we can start a new system with same configuration (esp. port collisions)" | |
(let [new-system-with-same-config (standard-sys test-config) | |
started-new-system (component/start new-system-with-same-config)] | |
(is (conn? (get-in started-new-system [:datomic-conn :conn]))) | |
(component/stop started-new-system)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment