monger.core tests now pass
This commit is contained in:
parent
d114073413
commit
d3cb048d2b
1 changed files with 23 additions and 25 deletions
|
|
@ -1,30 +1,27 @@
|
||||||
(ns monger.test.core-test
|
(ns monger.test.core-test
|
||||||
(:require [monger core collection util result]
|
(:require [monger util result]
|
||||||
[monger.test.helper :as helper]
|
[monger.core :as mg :refer [server-address mongo-options]]
|
||||||
[monger.collection :as mc]
|
[monger.collection :as mc]
|
||||||
[clojure.test :refer :all]
|
[clojure.test :refer :all])
|
||||||
[monger.core :refer [server-address mongo-options]])
|
|
||||||
(:import [com.mongodb MongoClient DB WriteConcern MongoClientOptions ServerAddress]))
|
(:import [com.mongodb MongoClient DB WriteConcern MongoClientOptions ServerAddress]))
|
||||||
|
|
||||||
(println (str "Using Clojure version " *clojure-version*))
|
(println (str "Using Clojure version " *clojure-version*))
|
||||||
(helper/connect!)
|
|
||||||
|
|
||||||
(deftest connect-to-mongo-with-default-host-and-port
|
(deftest connect-to-mongo-with-default-host-and-port
|
||||||
(let [connection (monger.core/connect)]
|
(let [connection (mg/connect)]
|
||||||
(is (instance? com.mongodb.MongoClient connection))))
|
(is (instance? com.mongodb.MongoClient connection))))
|
||||||
|
|
||||||
(deftest connect-and-disconnect
|
(deftest connect-and-disconnect
|
||||||
(monger.core/connect!)
|
(let [conn (mg/connect)]
|
||||||
(monger.core/disconnect!)
|
(mg/disconnect conn)))
|
||||||
(monger.core/connect!))
|
|
||||||
|
|
||||||
(deftest connect-to-mongo-with-default-host-and-explicit-port
|
(deftest connect-to-mongo-with-default-host-and-explicit-port
|
||||||
(let [connection (monger.core/connect { :port 27017 })]
|
(let [connection (mg/connect { :port 27017 })]
|
||||||
(is (instance? com.mongodb.MongoClient connection))))
|
(is (instance? com.mongodb.MongoClient connection))))
|
||||||
|
|
||||||
|
|
||||||
(deftest connect-to-mongo-with-default-port-and-explicit-host
|
(deftest connect-to-mongo-with-default-port-and-explicit-host
|
||||||
(let [connection (monger.core/connect { :host "127.0.0.1" })]
|
(let [connection (mg/connect { :host "127.0.0.1" })]
|
||||||
(is (instance? com.mongodb.MongoClient connection))))
|
(is (instance? com.mongodb.MongoClient connection))))
|
||||||
|
|
||||||
(deftest test-server-address
|
(deftest test-server-address
|
||||||
|
|
@ -36,31 +33,32 @@
|
||||||
|
|
||||||
(deftest use-existing-mongo-connection
|
(deftest use-existing-mongo-connection
|
||||||
(let [^MongoClientOptions opts (mongo-options :threads-allowed-to-block-for-connection-multiplier 300)
|
(let [^MongoClientOptions opts (mongo-options :threads-allowed-to-block-for-connection-multiplier 300)
|
||||||
connection (MongoClient. "127.0.0.1" opts)]
|
connection (MongoClient. "127.0.0.1" opts)
|
||||||
(monger.core/set-connection! connection)
|
db (mg/get-db connection "monger-test")]
|
||||||
(is (= monger.core/*mongodb-connection* connection))))
|
(mg/disconnect connection)))
|
||||||
|
|
||||||
(deftest connect-to-mongo-with-extra-options
|
(deftest connect-to-mongo-with-extra-options
|
||||||
(let [^MongoClientOptions opts (mongo-options :threads-allowed-to-block-for-connection-multiplier 300)
|
(let [^MongoClientOptions opts (mongo-options :threads-allowed-to-block-for-connection-multiplier 300)
|
||||||
^ServerAddress sa (server-address "127.0.0.1" 27017)]
|
^ServerAddress sa (server-address "127.0.0.1" 27017)
|
||||||
(monger.core/connect! sa opts)))
|
conn (mg/connect sa opts)]
|
||||||
|
(mg/disconnect conn)))
|
||||||
|
|
||||||
|
|
||||||
(deftest get-database
|
(deftest get-database
|
||||||
(let [connection (monger.core/connect)
|
(let [connection (mg/connect)
|
||||||
db (monger.core/get-db connection "monger-test")]
|
db (mg/get-db connection "monger-test")]
|
||||||
(is (instance? com.mongodb.DB db))))
|
(is (instance? com.mongodb.DB db))))
|
||||||
|
|
||||||
|
|
||||||
(deftest test-get-db-names
|
(deftest test-get-db-names
|
||||||
(let [dbs (monger.core/get-db-names)]
|
(let [conn (mg/connect)
|
||||||
|
dbs (mg/get-db-names conn)]
|
||||||
(is (not (empty? dbs)))
|
(is (not (empty? dbs)))
|
||||||
(is (dbs "monger-test"))))
|
(is (dbs "monger-test"))))
|
||||||
|
|
||||||
(deftest get-last-error
|
(deftest get-last-error
|
||||||
(let [connection (monger.core/connect)
|
(let [connection (mg/connect)
|
||||||
db (monger.core/get-db connection "monger-test")]
|
db (mg/get-db connection "monger-test")]
|
||||||
(is (monger.result/ok? (monger.core/get-last-error)))
|
(is (monger.result/ok? (mg/get-last-error db)))
|
||||||
(is (monger.result/ok? (monger.core/get-last-error db)))
|
(is (monger.result/ok? (mg/get-last-error db WriteConcern/NORMAL)))
|
||||||
(is (monger.result/ok? (monger.core/get-last-error db WriteConcern/NORMAL)))
|
(is (monger.result/ok? (mg/get-last-error db 1 100 true)))))
|
||||||
(is (monger.result/ok? (monger.core/get-last-error db 1 100 true)))))
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue