From e11d7d46713c14c5b7fded67d4909adc168b9823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Madeleine=20Sydney=20=C5=9Alaga?= Date: Mon, 23 Mar 2026 09:38:42 -0600 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=84=9C=EB=B2=84=EB=8A=94=20=EA=B8=B0?= =?UTF-8?q?=EC=B4=88=EC=9D=98=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=8D=94?= =?UTF-8?q?=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publisher/default.nix | 4 ++++ publisher/deps.edn | 5 +++- .../src/net/deertopia/publisher/server.clj | 12 ++++++---- .../net/deertopia/publisher/server_test.clj | 24 +++++++++++++++++++ publisher/tests.edn | 1 + 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 publisher/test/net/deertopia/publisher/server_test.clj create mode 100644 publisher/tests.edn diff --git a/publisher/default.nix b/publisher/default.nix index f8da10b..64335c8 100644 --- a/publisher/default.nix +++ b/publisher/default.nix @@ -20,4 +20,8 @@ mkCljBin { bb -cp . -m override-deps < deps.edn.old > deps.edn \ net.deertopia/doerg '{:local/root "${doerg.lib}/${doerg.name}.jar"}' ''; + doCheck = true; + checkPhase = '' + clojure -M:test + ''; } diff --git a/publisher/deps.edn b/publisher/deps.edn index f603fb7..130d5a8 100644 --- a/publisher/deps.edn +++ b/publisher/deps.edn @@ -13,4 +13,7 @@ http-kit/http-kit {:mvn/version "2.8.0"} instaparse/instaparse {:mvn/version "1.5.0"} aero/aero {:mvn/version "1.1.6"}} - :paths ["src" "resources" "test"]} + :paths ["src" "resources" "test"] + :aliases + {:test {:extra-deps {lambdaisland/kaocha {:mvn/version "1.91.1392"}} + :main-opts ["-m" "kaocha.runner"]}}} diff --git a/publisher/src/net/deertopia/publisher/server.clj b/publisher/src/net/deertopia/publisher/server.clj index 78330d2..e1012eb 100644 --- a/publisher/src/net/deertopia/publisher/server.clj +++ b/publisher/src/net/deertopia/publisher/server.clj @@ -98,8 +98,7 @@ (defn start! [] (if @server - (let [msg "Server already started"] - (throw (ex-info msg {}))) + (throw (IllegalStateException. "Server already started")) (do (reset! server (http/run-server (bound-fn* #'app) {:port (-> cfg/*cfg* ::publisher/port) @@ -107,8 +106,13 @@ ;; For some reason, the log messages are not flushed before ;; the JVM shuts dowm. Nevertheless, the server /does/ come ;; to a graceful halt. - (.addShutdownHook (Runtime/getRuntime) shutdown-hook) - (l/info "Server started on port 8080")))) + (try (.addShutdownHook (Runtime/getRuntime) shutdown-hook) + (catch IllegalArgumentException e + (when (not= "Hook previously registered" + (ex-message e)) + (throw e)))) + (l/infof "Server started on port %d" + (-> cfg/*cfg* ::publisher/port))))) (defn status [] (if @server diff --git a/publisher/test/net/deertopia/publisher/server_test.clj b/publisher/test/net/deertopia/publisher/server_test.clj new file mode 100644 index 0000000..1ecd853 --- /dev/null +++ b/publisher/test/net/deertopia/publisher/server_test.clj @@ -0,0 +1,24 @@ +(ns net.deertopia.publisher.server-test + (:require [net.deertopia.publisher.server :as sut] + [reitit.ring] + [clojure.test :as t] + [clojure.set :as set] + [net.deertopia.publisher.server :as server] + [net.deertopia.publisher.config :as cfg] + [net.deertopia.publisher :as-alias publisher])) + +(t/deftest server-is-running + ;; 서버는 시작 전에 이 검서 하면 고장 있습니다. + (assert (not= :running (server/status))) + (server/start!) + (t/is (= :running (server/status))) + (server/stop!)) + +(t/deftest can-get-real-server-root + ;; 서버는 시작 전에 이 검서 하면 고장 있습니다. + (assert (not= :running (server/status))) + (server/start!) + (t/is (->> (format "http://localhost:%d" (::publisher/port cfg/*cfg*)) + slurp + string?)) + (server/stop!)) diff --git a/publisher/tests.edn b/publisher/tests.edn new file mode 100644 index 0000000..9d8d845 --- /dev/null +++ b/publisher/tests.edn @@ -0,0 +1 @@ +#kaocha/v1 {}