-
-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setup tests to run in repl without interfering with development setup
Use with-redefs and fixtures to create the test config. This allows the repl to run the tests without resetting the development database, events, etc. Move the test-resources into dev-resources
- Loading branch information
Showing
17 changed files
with
42 additions
and
38 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -15,6 +15,26 @@ | |
(def local-repo2 (io/file (System/getProperty "java.io.tmpdir") | ||
"clojars" "test" "local-repo2")) | ||
|
||
(def test-config {:db {:classname "org.sqlite.JDBC" | ||
:subprotocol "sqlite" | ||
:subname "data/test_db"} | ||
:key-file "data/test/authorized_keys" | ||
:repo "data/test/repo" | ||
:event-dir "data/test/events" | ||
:stats-dir "data/test/stats" | ||
:index-path "data/test/index" | ||
:bcrypt-work-factor 12 | ||
:mail {:hostname "smtp.gmail.com" | ||
:from "[email protected]" | ||
:username "[email protected]" | ||
:password "fuuuuuu" | ||
:port 465 ; If you change ssl to false, the port might not be effective, search for .setSSL and .setSslSmtpPort | ||
:ssl true}}) | ||
|
||
(defn using-test-config [f] | ||
(with-redefs [config test-config] | ||
(f))) | ||
|
||
(defn delete-file-recursively | ||
"Delete file f. If it's a directory, recursively delete all its contents." | ||
[f] | ||
|
@@ -47,18 +67,20 @@ | |
(clucy/add index a))))) | ||
|
||
(defn default-fixture [f] | ||
(force migrate) | ||
(delete-file-recursively (io/file (config :repo))) | ||
(delete-file-recursively (io/file (config :event-dir))) | ||
(.mkdirs (io/file (config :event-dir))) | ||
(delete-file-recursively (io/file (config :stats-dir))) | ||
(.mkdirs (io/file (config :stats-dir))) | ||
(make-download-count! {}) | ||
(jdbc/with-connection (kdb/get-connection @kdb/_default) | ||
(jdbc/do-commands | ||
"delete from users;" "delete from jars;" "delete from groups;")) | ||
(f)) | ||
(using-test-config | ||
(fn [] | ||
(force migrate) | ||
(delete-file-recursively (io/file (config :repo))) | ||
(delete-file-recursively (io/file (config :event-dir))) | ||
(.mkdirs (io/file (config :event-dir))) | ||
(delete-file-recursively (io/file (config :stats-dir))) | ||
(.mkdirs (io/file (config :stats-dir))) | ||
(make-download-count! {}) | ||
(jdbc/with-connection (kdb/get-connection @kdb/_default) | ||
(jdbc/do-commands | ||
"delete from users;" "delete from jars;" "delete from groups;")) | ||
(f)))) | ||
|
||
(defn index-fixture [f] | ||
(make-index! []) | ||
(f)) | ||
(f)) |
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 |
---|---|---|
|
@@ -42,7 +42,7 @@ | |
(copy-resource "1.1.2" "jar.asc") | ||
(copy-resource "1.1.2" "pom.asc") | ||
(db/add-user "[email protected]" "testuser" "password" "asdf" | ||
(slurp "test-resources/pubring.gpg")) | ||
(slurp (io/resource "pubring.gpg"))) | ||
(db/add-member "robert" "testuser" nil) | ||
(is (empty? (blockers {:group "robert" :name "hooke" :version "1.1.2"})))) | ||
|
||
|
@@ -53,7 +53,7 @@ | |
(copy-resource "1.1.2" "jar.asc") | ||
(copy-resource "1.1.2" "pom.asc") | ||
(db/add-user "[email protected]" "testuser" "password" "asdf" | ||
(slurp "test-resources/pubring.gpg")) | ||
(slurp (io/resource "pubring.gpg"))) | ||
(db/add-member "robert" "testuser" nil) | ||
(is (= [(str "Could not verify signature of " | ||
(config :repo) "/robert/hooke/1.1.2/hooke-1.1.2.jar. " | ||
|
@@ -75,4 +75,4 @@ | |
(str "Could not verify signature of " | ||
(config :repo) "/robert/hooke/1.1.2/hooke-1.1.2.pom. " | ||
"Ensure your public key is in your profile.")] | ||
(blockers {:group "robert" :name "hooke" :version "1.1.2"})))) | ||
(blockers {:group "robert" :name "hooke" :version "1.1.2"})))) |
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