-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dce96bf
commit 7afc2d4
Showing
173 changed files
with
27,691 additions
and
77 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/bin/bash -e | ||
|
||
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")" | ||
. "$SCRIPT_DIR/util.sh" | ||
|
||
BASE="http://localhost:8080/fhir" | ||
|
||
echo "checking index.html using the Accept header..." | ||
HEADERS=$(curl -s -H 'Accept: text/html' -o /dev/null -D - "$BASE") | ||
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2) | ||
|
||
test "Content-Type header" "$CONTENT_TYPE_HEADER" "text/html" | ||
|
||
echo "checking index.html using the _format query param..." | ||
HEADERS=$(curl -s -o /dev/null -D - "$BASE?_format=html") | ||
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2) | ||
|
||
test "Content-Type header" "$CONTENT_TYPE_HEADER" "text/html" | ||
|
||
echo "checking version.json..." | ||
HEADERS=$(curl -s -H 'Accept: text/html' -o /dev/null -D - "$BASE/__frontend/version.json") | ||
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2) | ||
|
||
test "Content-Type header" "$CONTENT_TYPE_HEADER" "application/json" | ||
|
||
echo "checking system-search using the Accept header..." | ||
HEADERS=$(curl -s -H 'Accept: application/fhir+json' -o /dev/null -D - "$BASE") | ||
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2) | ||
|
||
test "Content-Type header" "$CONTENT_TYPE_HEADER" "application/fhir+json;charset=utf-8" | ||
|
||
echo "checking system-search using the _format query param..." | ||
HEADERS=$(curl -s -o /dev/null -D - "$BASE?_format=json") | ||
CONTENT_TYPE_HEADER=$(echo "$HEADERS" | grep -i 'Content-Type' | tr -d '\r' | cut -d' ' -f2) | ||
|
||
test "Content-Type header" "$CONTENT_TYPE_HEADER" "application/fhir+json;charset=utf-8" |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{:lint-as | ||
{blaze.admin-api-test/with-handler clojure.core/fn} | ||
|
||
:linters | ||
{:unsorted-required-namespaces | ||
{:level :error} | ||
|
||
:single-key-in | ||
{:level :warning} | ||
|
||
:keyword-binding | ||
{:level :error} | ||
|
||
:reduce-without-init | ||
{:level :warning} | ||
|
||
:warn-on-reflection | ||
{:level :warning :warn-only-on-interop true} | ||
|
||
:consistent-alias | ||
{:aliases | ||
{blaze.async.comp ac | ||
blaze.db.kv.rocksdb rocksdb | ||
clojure.spec.alpha s | ||
integrant.core ig | ||
ring.util.response ring | ||
taoensso.timbre log}}} | ||
|
||
:skip-comments true} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
lint: | ||
clj-kondo --lint src test deps.edn | ||
|
||
prep: | ||
clojure -X:deps prep | ||
|
||
test: prep | ||
clojure -M:test:kaocha --profile :ci | ||
|
||
test-coverage: prep | ||
clojure -M:test:coverage | ||
|
||
clean: | ||
rm -rf .clj-kondo/.cache .cpcache target | ||
|
||
.PHONY: lint prep test test-coverage clean |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{:deps | ||
{blaze/async | ||
{:local/root "../async"} | ||
|
||
blaze/module-base | ||
{:local/root "../module-base"} | ||
|
||
blaze/rest-util | ||
{:local/root "../rest-util"} | ||
|
||
blaze/rocksdb | ||
{:local/root "../rocksdb"} | ||
|
||
blaze/spec | ||
{:local/root "../spec"}} | ||
|
||
:aliases | ||
{:test | ||
{:extra-paths ["test"] | ||
|
||
:extra-deps | ||
{blaze/test-util | ||
{:local/root "../test-util"}}} | ||
|
||
:kaocha | ||
{:extra-deps | ||
{lambdaisland/kaocha | ||
{:mvn/version "1.71.1119"}} | ||
|
||
:main-opts ["-m" "kaocha.runner"]} | ||
|
||
:coverage | ||
{:extra-deps | ||
{cloverage/cloverage | ||
{:mvn/version "1.2.4"}} | ||
|
||
:main-opts ["-m" "cloverage.coverage" "--codecov" "-p" "src" "-s" "test"]}}} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
(ns blaze.admin-api | ||
(:require | ||
[blaze.async.comp :as ac] | ||
[blaze.db.kv.rocksdb :as rocksdb] | ||
[blaze.spec] | ||
[clojure.spec.alpha :as s] | ||
[integrant.core :as ig] | ||
[reitit.ring] | ||
[reitit.ring.spec] | ||
[ring.util.response :as ring] | ||
[taoensso.timbre :as log])) | ||
|
||
|
||
(defn- rocksdb-column-families-handler [index-kv-store] | ||
(fn [_] | ||
(-> (ring/response | ||
{:column-families (mapv name (rocksdb/column-families index-kv-store))}) | ||
(ac/completed-future)))) | ||
|
||
|
||
(defn- rocksdb-table-handler [index-kv-store] | ||
(fn [{{:keys [column-family]} :path-params}] | ||
(-> (ring/response {:tables (rocksdb/table-properties index-kv-store (keyword column-family))}) | ||
(ac/completed-future)))) | ||
|
||
|
||
(defn- router [{:keys [context-path index-kv-store] :or {context-path ""}}] | ||
(reitit.ring/router | ||
["/rocksdb" | ||
{} | ||
["/index" | ||
{} | ||
["/column-families" | ||
{} | ||
["" | ||
{:get (rocksdb-column-families-handler index-kv-store)}] | ||
["/{column-family}" | ||
{} | ||
["/tables" | ||
{:get (rocksdb-table-handler index-kv-store)}]]]]] | ||
{:path (str context-path "/__admin") | ||
:syntax :bracket})) | ||
|
||
|
||
(defmethod ig/pre-init-spec :blaze/admin-api [_] | ||
(s/keys :req-un [:blaze/context-path :blaze.db/index-kv-store])) | ||
|
||
|
||
(defmethod ig/init-key :blaze/admin-api | ||
[_ context] | ||
(log/info "Init Admin endpoint") | ||
(reitit.ring/ring-handler | ||
(router context) | ||
(fn [{:keys [uri]}] | ||
(-> (ring/not-found {:uri uri}) | ||
(ac/completed-future))))) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
(ns blaze.admin-api-test | ||
(:require | ||
[blaze.admin-api] | ||
[blaze.db.kv.rocksdb.protocols :as p] | ||
[blaze.test-util :as tu :refer [given-thrown with-system]] | ||
[clojure.spec.alpha :as s] | ||
[clojure.spec.test.alpha :as st] | ||
[clojure.test :as test :refer [deftest testing]] | ||
[integrant.core :as ig] | ||
[juxt.iota :refer [given]] | ||
[taoensso.timbre :as log])) | ||
|
||
|
||
(st/instrument) | ||
(log/set-level! :trace) | ||
|
||
|
||
(test/use-fixtures :each tu/fixture) | ||
|
||
|
||
(deftest init-test | ||
(testing "nil config" | ||
(given-thrown (ig/init {:blaze/admin-api nil}) | ||
:key := :blaze/admin-api | ||
:reason := ::ig/build-failed-spec | ||
[:explain ::s/problems 0 :pred] := `map?)) | ||
|
||
(testing "missing config" | ||
(given-thrown (ig/init {:blaze/admin-api {}}) | ||
:key := :blaze/admin-api | ||
:reason := ::ig/build-failed-spec | ||
[:explain ::s/problems 0 :pred] := `(fn ~'[%] (contains? ~'% :context-path)) | ||
[:explain ::s/problems 1 :pred] := `(fn ~'[%] (contains? ~'% :index-kv-store)))) | ||
|
||
(testing "invalid index-kv-store" | ||
(given-thrown (ig/init {:blaze/admin-api {:index-kv-store ::invalid}}) | ||
:key := :blaze/admin-api | ||
:reason := ::ig/build-failed-spec | ||
[:explain ::s/problems 0 :pred] := `(fn ~'[%] (contains? ~'% :context-path))))) | ||
|
||
|
||
(defmethod ig/init-key ::rocksdb | ||
[_ {:keys [column-families]}] | ||
(reify p/Rocks | ||
(-column-families [_] | ||
(keys column-families)) | ||
|
||
(-table-properties [_ column-family] | ||
(when (column-families column-family) | ||
[{:name (str (name column-family) "/table-1") | ||
:data-size 193338}])))) | ||
|
||
|
||
(def config | ||
{:blaze/admin-api | ||
{:context-path "/fhir" | ||
:index-kv-store (ig/ref :blaze.db/index-kv-store)} | ||
|
||
[::rocksdb :blaze.db/index-kv-store] | ||
{:column-families | ||
{:column-family-1 {} | ||
:column-family-2 {}}}}) | ||
|
||
|
||
(defmacro with-handler [[handler-binding] & body] | ||
`(with-system [{handler# :blaze/admin-api} config] | ||
(let [~handler-binding handler#] | ||
~@body))) | ||
|
||
|
||
(deftest rocksdb-column-families-test | ||
(with-handler [handler] | ||
(testing "success" | ||
(given @(handler | ||
{:request-method :get | ||
:uri "/fhir/__admin/rocksdb/index/column-families"}) | ||
:status := 200 | ||
[:body :column-families] := ["column-family-1" "column-family-2"])))) | ||
|
||
|
||
(deftest rocksdb-tables-test | ||
(with-handler [handler] | ||
(testing "not found" | ||
(given @(handler | ||
{:request-method :get | ||
:uri "/fhir/__admin/foo"}) | ||
:status := 404)) | ||
|
||
(testing "success" | ||
(given @(handler | ||
{:request-method :get | ||
:uri "/fhir/__admin/rocksdb/index/column-families/column-family-1/tables"}) | ||
:status := 200 | ||
[:body :tables 0 :name] := "column-family-1/table-1" | ||
[:body :tables 0 :data-size] := 193338)))) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#kaocha/v1 | ||
#merge | ||
[{} | ||
#profile {:ci {:reporter kaocha.report/documentation | ||
:color? false}}] |
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
Oops, something went wrong.