Skip to content
Snippets Groups Projects
Unverified Commit 40aeafab authored by Cal Herries's avatar Cal Herries Committed by GitHub
Browse files

Avoid changing H2 DB files when running tests (#29472)

* Avoid updating tiny-db in ssh test

* Avoid updating sample-database during testing

* Fix write test
parent d17e8b75
No related branches found
No related tags found
No related merge requests found
......@@ -20,8 +20,11 @@
;; These tools are pretty sophisticated for the amount of tests we have!
(defn- sample-database-db []
{:details (#'sample-data/try-to-extract-sample-database!)
(defn- sample-database-db [read-write?]
;; If `read-write?` is false, open the DB in read-only mode so we don't accidentally modify it during testing
{:details (cond-> (#'sample-data/try-to-extract-sample-database!)
(not read-write?)
(update :db #(str % ";ACCESS_MODE_DATA=r")))
:engine :h2
:name "Sample Database"})
......@@ -29,7 +32,7 @@
"Execute `body` with a temporary Sample Database DB bound to `db-binding`."
{:style/indent 1}
[[db-binding] & body]
`(mt/with-temp Database [db# (sample-database-db)]
`(mt/with-temp Database [db# (sample-database-db false)]
(sync/sync-database! db#)
(let [~db-binding db#]
~@body)))
......@@ -47,7 +50,7 @@
;;; ----------------------------------------------------- Tests ------------------------------------------------------
(def ^:private extracted-db-path-regex #"^file:.*plugins/sample-database.db;USER=GUEST;PASSWORD=guest$")
(def ^:private extracted-db-path-regex #"^file:.*plugins/sample-database.db;USER=GUEST;PASSWORD=guest.*")
(deftest extract-sample-database-test
(testing "The Sample Database is copied out of the JAR into the plugins directory before the DB details are saved."
......@@ -104,7 +107,8 @@
(deftest write-rows-sample-database-test
(testing "should be able to execute INSERT, UPDATE, and DELETE statements on the Sample Database"
(with-temp-sample-database-db [db]
(mt/with-temp Database [db (sample-database-db true)]
(sync/sync-database! db)
(mt/with-db db
(let [conn-spec (sql-jdbc.conn/db->pooled-connection-spec (mt/db))]
(testing "update row"
......
......@@ -251,7 +251,8 @@
(testing "ssh tunnel is reestablished if it becomes closed, so subsequent queries still succeed (H2 version)"
(let [h2-port (tu/find-free-port)
server (init-h2-tcp-server h2-port)
uri (format "tcp://localhost:%d/./test_resources/ssh/tiny-db;USER=GUEST;PASSWORD=guest" h2-port)
; Use ACCESS_MODE_DATA=r to avoid updating the DB file
uri (format "tcp://localhost:%d/./test_resources/ssh/tiny-db;USER=GUEST;PASSWORD=guest;ACCESS_MODE_DATA=r" h2-port)
h2-db {:port h2-port
:host "localhost"
:db uri
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment