Skip to content

Commit

Permalink
Setup tests to run in repl without interfering with development setup
Browse files Browse the repository at this point in the history
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
xeqi committed Oct 7, 2013
1 parent 7c940a9 commit 2801a63
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 38 deletions.
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.
6 changes: 1 addition & 5 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@
[clucy "0.3.0"]
[org.clojure/tools.nrepl "0.2.3"]
[org.bouncycastle/bcpg-jdk15on "1.47"]]
:profiles {:test {:resource-paths ["test-resources"]
:dependencies [[kerodon "0.0.7"]
[nailgun-shim "0.0.1"]]}
:dev {:dependencies [[kerodon "0.0.7"]
:profiles {:dev {:dependencies [[kerodon "0.0.7"]
[nailgun-shim "0.0.1"]]
;; TODO: set test resources in fixture w/ with-redefs
:resource-paths ["local-resources"]}}
:plugins [[lein-ring "0.8.5"]]
:aliases {"migrate" ["run" "-m" "clojars.db.migrate"]}
Expand Down
13 changes: 0 additions & 13 deletions test-resources/config.clj

This file was deleted.

46 changes: 34 additions & 12 deletions test/clojars/test/test_helper.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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))
6 changes: 3 additions & 3 deletions test/clojars/test/unit/maven.clj
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
[{:group_name "org.clojure", :jar_name "clojure", :version "1.3.0-beta1" :scope "compile"}
{:group_name "org.clojurer", :jar_name "clojure", :version "1.6.0" :scope "provided"}
{:group_name "midje", :jar_name "midje", :version "1.3-alpha4", :scope "test"}]
(:dependencies (pom-to-map "test-resources/test-maven/test-maven.pom")))))
(:dependencies (pom-to-map (.toString (io/resource "test-maven/test-maven.pom")))))))

(deftest directory-for-handles-normal-group-name
(is (= (io/file (config :repo) "fake" "test" "1.0.0")
(directory-for {:group_name "fake"
:jar_name "test"
:version "1.0.0"})))
)
:version "1.0.0"}))))

(deftest directory-for-handles-group-names-with-dots
(is (= (io/file (config :repo) "com" "novemberain" "monger" "1.2.0-alpha1")
(directory-for {:group_name "com.novemberain"
Expand Down
6 changes: 3 additions & 3 deletions test/clojars/test/unit/promote.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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"}))))

Expand All @@ -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. "
Expand All @@ -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"}))))
3 changes: 1 addition & 2 deletions test/clojars/test/unit/search.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
[clojure.test :refer :all]
[clojars.test.test-helper :as help]))

(use-fixtures :each
help/default-fixture)
(use-fixtures :each help/default-fixture)

(deftest weight-by-downloads
(help/make-download-count! {["asd" "alfred"] {"0.0.1" 1}
Expand Down

0 comments on commit 2801a63

Please sign in to comment.