feat: 테스트 데이터베이스
All checks were successful
build / build (push) Successful in 5s

해결 #28
This commit was merged in pull request #30.
This commit is contained in:
2026-03-28 10:36:10 -06:00
parent 9cc0def4d5
commit cf242b778d
10 changed files with 99 additions and 27 deletions

View File

@@ -68,4 +68,5 @@ in mkCljBin' {
checkPhase = ''
clojure -M:test
'';
passthru = { inherit plex our-tex; };
}

6
flake.lock generated
View File

@@ -111,11 +111,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1760038930,
"narHash": "sha256-Oncbh0UmHjSlxO7ErQDM3KM0A5/Znfofj2BSzlHLeVw=",
"lastModified": 1774386573,
"narHash": "sha256-4hAV26quOxdC6iyG7kYaZcM3VOskcPUrdCQd/nx8obc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "0b4defa2584313f3b781240b29d61f6f9f7e0df3",
"rev": "46db2e09e1d3f113a13c0d7b81e2f221c63b8ce9",
"type": "github"
},
"original": {

View File

@@ -57,6 +57,7 @@
default = pkgs.mkShell {
inputsFrom = [
pkgs.doerg
pkgs.publisher
pkgs.doerg-parser
pkgs.doerg-temml-worker
];
@@ -68,6 +69,7 @@
clojure
babashka
sqlite-web
pkgs.publisher.test-emacs
];
};
});

View File

@@ -1,9 +1,25 @@
{ mkCljBin
, doerg
, babashka
, callPackage
, test-emacs ? callPackage ./test-emacs.nix {}
, fake-git
, breakpointHook
, doerg-temml-worker
, doerg-parser
}:
mkCljBin {
let
# 이 mkCljBin에는 fake-git가 포함되지 않는다. 그것 불필요해서 dev
# shell에 없고 싶는다.
mkCljBin' = args: (mkCljBin args).overrideAttrs (final: prev: {
nativeBuildInputs =
builtins.filter
# A possibly-sketchy predicate, lol.
(x: x != fake-git)
prev.nativeBuildInputs;
});
in mkCljBin' {
name = "net.deertopia/publisher";
version = "0.1.0";
projectSrc = ./.;
@@ -14,6 +30,15 @@ mkCljBin {
];
nativeBuildInputs = [
babashka
breakpointHook
];
nativeCheckInputs = [
doerg-parser
doerg-temml-worker
test-emacs
doerg
doerg.our-tex
doerg.plex
];
postPatch = ''
mv deps.edn deps.edn.old
@@ -22,6 +47,10 @@ mkCljBin {
'';
doCheck = true;
checkPhase = ''
export \
EMACS=test-emacs \
XDG_STATE_HOME=$(mktemp -d "state-home-XXXXXX")
clojure -M:test
'';
passthru = { inherit test-emacs; };
}

View File

@@ -4,5 +4,5 @@
"/doerg-publisher"]
:org-roam-db-path
#profile {:default #join [#env HOME "/.cache/emacs/org-roam.db"]
:test #file "../../../../test/net/deertopia/publisher/roam-test.db"}
:test #join [#or [#env TMP "/tmp"] "/doerg-org-roam-test.db"]}
:port #profile {:default 8080}}

View File

@@ -97,9 +97,6 @@
(assoc-in [:path-params :slug] homepage-slug)
node-by-slug))
(def doerg-resources
#{"Temml-Plex.css" "tuftesque.css" "deerstar.css"})
(defn handle-resource [{:keys [uri]}]
(if-some [[_ resource] (re-matches #"^/resource/ibm-plex-web/(.*)" uri)]
(-> resource

10
publisher/test-emacs.nix Normal file
View File

@@ -0,0 +1,10 @@
{ emacsPackages
, symlinkJoin
, writeScriptBin
, lib
}:
let emacs = emacsPackages.emacsWithPackages (epkgs: [ epkgs.org-roam ]);
in writeScriptBin "test-emacs" ''
exec ${lib.getExe emacs} "$@"
''

View File

@@ -0,0 +1,8 @@
#!/usr/bin/env -S emacs -Q -x
(require 'org-roam)
(setq org-roam-directory (expand-file-name (car command-line-args-left)))
(setq org-roam-db-location (expand-file-name (cadr command-line-args-left)))
(org-roam-db-sync)

View File

@@ -6,7 +6,13 @@
[net.deertopia.doerg.config :as doerg-cfg]
[net.deertopia.publisher :as-alias publisher]
[net.deertopia.doerg :as-alias doerg]
[net.deertopia.publisher.roam :as roam]))
[net.deertopia.publisher.roam :as roam]
[babashka.fs :as fs]
[babashka.process :as p]
[clojure.java.io :as io]))
(def org-roam-directory
(fs/file "test/net/deertopia/publisher/roam-test"))
(defn config-fixture [f]
(binding [doerg-cfg/*cfg*
@@ -19,8 +25,27 @@
:profile :test)]
(f)))
(defn org-roam-db-sync [db-file]
(let [script-file (fs/create-temp-file {:prefix "org-roam-db-sync-"
:suffix ".el"})
emacs (->> [(System/getenv "EMACS") "test-emacs" "emacs"]
(some #(some-> % fs/which)))]
(io/copy (-> "net/deertopia/publisher/org-roam-db-sync.el"
io/resource io/reader)
(fs/file script-file))
(p/shell {:out :string :err :string}
emacs "-Q" "-x" script-file org-roam-directory db-file)
(fs/delete script-file)))
(defn test-db-fixture [f]
(let [db-file (-> publisher-cfg/*cfg* ::publisher/org-roam-db-path)]
(fs/delete-if-exists db-file)
(org-roam-db-sync db-file)
(f)
(fs/delete db-file)))
(t/use-fixtures
:once config-fixture)
:once (t/join-fixtures [config-fixture test-db-fixture]))
(defn with-server [f]
(let [was-already-running? (= :running (sut/status))]
@@ -34,6 +59,8 @@
(sut/app {:request-method :get
:uri uri}))
(t/deftest server-is-running
;; 서버는 벌써 시작한 다음에 이 테스트 하면 잘못됩니다.
;; (assert (not= :running (sut/status)))
@@ -41,25 +68,23 @@
(fn []
(t/is (= :running (sut/status)))
;; 테스트 데이터베이스를 아직 안 준비한다.
#_(t/is (->> (format "http://localhost:%d"
(t/is (->> (format "http://localhost:%d"
(::publisher/port publisher-cfg/*cfg*))
slurp
string?)))))
(comment
;; 테스트 데이터베이스를 아직 안 준비한다.
(t/deftest get-nonexistent-node
(let [slug "3Lxvxnb0QrivoU3DX-l_5w"]
(assert (nil? (roam/make-node slug)))
(t/is (= 404
(-> (str "/n/" slug)
get-sut :status))))))
get-sut :status)))))
(comment
;; 테스트 데이터베이스를 아직 안 준비한다.
(t/deftest get-homepage
(let [resp (-> (str "/n/" sut/homepage-slug)
get-sut)]
(t/is (= 200 (:status resp)))
(t/is (= (-> "/" get-sut :body)
(-> resp :body))))))
(-> resp :body)))))