Add postgres test
This commit is contained in:
parent
94f9bce08c
commit
88eb4c569d
3 changed files with 56 additions and 0 deletions
|
|
@ -38,6 +38,7 @@ jobs:
|
|||
- run:
|
||||
name: Run JVM tests
|
||||
command: |
|
||||
script/postgres_test
|
||||
script/test
|
||||
script/run_lib_tests
|
||||
# - run:
|
||||
|
|
|
|||
13
script/postgres_test
Executable file
13
script/postgres_test
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
docker run --name babashka-postgres -p 54322:5432 -e POSTGRES_PASSWORD=mysecretpassword -d postgres
|
||||
|
||||
if [ "$BABASHKA_TEST_ENV" = "native" ]; then
|
||||
BB_CMD="./bb"
|
||||
else
|
||||
BB_CMD="lein bb"
|
||||
fi
|
||||
|
||||
"$BB_CMD" -f test-resources/babashka/postgres_test.clj
|
||||
|
||||
docker rm -f babashka-postgres
|
||||
42
test-resources/babashka/postgres_test.clj
Normal file
42
test-resources/babashka/postgres_test.clj
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
(ns babashka.postgres-test
|
||||
(:require [clojure.test :as t :refer [deftest is]]
|
||||
[next.jdbc :as jdbc]
|
||||
[next.jdbc.sql :as sql]))
|
||||
|
||||
(def db {:dbtype "postgres"
|
||||
:port 54322
|
||||
:dbname "postgres"
|
||||
:user "postgres"
|
||||
:password "mysecretpassword"})
|
||||
|
||||
(defmethod clojure.test/report :begin-test-var [m]
|
||||
(println "===" (-> m :var meta :name))
|
||||
(println))
|
||||
|
||||
(defn wait-for-postgres []
|
||||
(while
|
||||
(not
|
||||
(try (jdbc/execute! db ["select version()"])
|
||||
(catch Exception _
|
||||
(Thread/sleep 100))))))
|
||||
|
||||
(deftest create-table-test
|
||||
(is (jdbc/execute! db ["drop table if exists foo; create table foo ( foo text )"])))
|
||||
|
||||
(deftest insert-test
|
||||
(is (sql/insert-multi! db :foo [:foo] [["foo"] ["bar"] ["baz"]])))
|
||||
|
||||
(deftest query-test
|
||||
(let [results (jdbc/execute! db ["select * from foo"])]
|
||||
(is (= '[{:foo/foo "foo"} {:foo/foo "bar"} {:foo/foo "baz"}]
|
||||
results))))
|
||||
|
||||
(defn test-ns-hook []
|
||||
(wait-for-postgres)
|
||||
(create-table-test)
|
||||
(insert-test)
|
||||
(query-test))
|
||||
|
||||
(let [{:keys [:fail :error]}
|
||||
(t/run-tests)]
|
||||
(System/exit (+ fail error)))
|
||||
Loading…
Reference in a new issue