Skip to content

Commit

Permalink
add test for backing out reserved issue with tx/no-tx (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
leblowl authored and yogthos committed Jul 8, 2018
1 parent 50e8bee commit cdc4e36
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- :disable-transaction
DROP TABLE quux2;
--;;
DROP TABLE quux3;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
-- :disable-transaction

CREATE TABLE
quux2
(id bigint,
name varchar(255));

--;;
THIS IS MOST DEFINITELY NOT VALID SQL;

--;;

CREATE TABLE
quux3
(id bigint,
name varchar(255));
18 changes: 13 additions & 5 deletions test/migratus/test/database.clj
Original file line number Diff line number Diff line change
Expand Up @@ -235,18 +235,26 @@
(= java.sql.Timestamp))
from-db)))))


(deftest test-backing-out-bad-migration
(log/debug "running backout tests")
(let [{:keys [db migration-table-name] :as test-config} (assoc config :migration-dir "migrations-intentionally-broken")]
(defn- test-backing-out* [test-config]
(let [{:keys [db migration-table-name]} test-config]
(testing "should fail")
(is (thrown? Throwable (core/migrate test-config)))
(testing "first statement in migration was backed out because second one failed")
(is (not (test-sql/verify-table-exists? test-config "quux2")))
(testing "third statement in migration was backed out because second one failed")
(is (not (test-sql/verify-table-exists? test-config "quux3")))
(testing "migration was not applied")
(is (not (complete? db migration-table-name 20120827170200)))))
(is (not (complete? db migration-table-name 20120827170200)))
(testing "table should be unreserved after migration failure")
(is (mark-reserved db migration-table-name))))

(deftest test-backing-out-bad-migration
(log/debug "running backout tests")
(test-backing-out* (assoc config :migration-dir "migrations-intentionally-broken")))

(deftest test-backing-out-bad-migration-no-tx
(log/debug "running backout tests without tx")
(test-backing-out* (assoc config :migration-dir "migrations-intentionally-broken-no-tx")))


(deftest test-no-tx-migration
Expand Down

0 comments on commit cdc4e36

Please sign in to comment.