Cursor tests now pass

This commit is contained in:
Michael Klishin 2014-05-11 13:19:19 -04:00
parent 6acfb43314
commit c29587f66d

View file

@ -1,19 +1,18 @@
(ns monger.test.cursor-test (ns monger.test.cursor-test
(:import [com.mongodb DBCursor DBObject Bytes] (:import [com.mongodb DBCursor DBObject Bytes]
[java.util List Map]) [java.util List Map])
(:require [monger.test.helper :as helper] (:require [monger.core :as mg]
[clojure.test :refer :all] [clojure.test :refer :all]
[monger.cursor :refer :all] [monger.cursor :refer :all]))
[monger.test.fixtures :refer :all]))
(helper/connect!) (let [conn (mg/connect)
db (mg/get-db conn "monger-test")]
(deftest make-db-cursor-for-collection (deftest make-db-cursor-for-collection
(is (= DBCursor (is (= DBCursor
(class (make-db-cursor :docs))))) (class (make-db-cursor db :docs)))))
(deftest getting-cursor-options-value (deftest getting-cursor-options-value
(let [db-cur (make-db-cursor :docs) (let [db-cur (make-db-cursor db :docs)
opts (get-options db-cur)] opts (get-options db-cur)]
(is (= true (isa? (class opts) Map))) (is (= true (isa? (class opts) Map)))
(is (= 0 (.getOptions db-cur))) ;;test default value (is (= 0 (.getOptions db-cur))) ;;test default value
@ -24,8 +23,8 @@
(is (= false (:slaveok opts))) (is (= false (:slaveok opts)))
(is (= false (:tailable opts))))) (is (= false (:tailable opts)))))
(deftest adding-option-to-cursor (deftest adding-option-to-cursor
(let [db-cur (make-db-cursor :docs)] (let [db-cur (make-db-cursor db :docs)]
(add-option! db-cur :notimeout) (add-option! db-cur :notimeout)
(is (= (:notimeout cursor-options) (is (= (:notimeout cursor-options)
(.getOptions db-cur))) (.getOptions db-cur)))
@ -36,8 +35,8 @@
(:tailable cursor-options) (:tailable cursor-options)
(:awaitdata cursor-options)))))) (:awaitdata cursor-options))))))
(deftest remove-option-from-cursor (deftest remove-option-from-cursor
(let [db-cur (make-db-cursor :docs)] (let [db-cur (make-db-cursor db :docs)]
(add-option! db-cur :partial) (add-option! db-cur :partial)
(add-option! db-cur :awaitdata) (add-option! db-cur :awaitdata)
;; removing not-set option should not affect result ;; removing not-set option should not affect result
@ -51,16 +50,16 @@
(:partial cursor-options))))) (:partial cursor-options)))))
(deftest test-reset-options (deftest test-reset-options
(let [db-cur (make-db-cursor :docs)] (let [db-cur (make-db-cursor db :docs)]
(add-option! db-cur :partial) (add-option! db-cur :partial)
(is (= (.getOptions db-cur) (is (= (.getOptions db-cur)
(:partial cursor-options))) (:partial cursor-options)))
(is (= 0 (is (= 0
(int (.getOptions (reset-options db-cur))))))) (int (.getOptions (reset-options db-cur)))))))
(deftest add-options-with-hashmap (deftest add-options-with-hashmap
(let [db-cur (make-db-cursor :docs) (let [db-cur (make-db-cursor db :docs)
_ (add-options db-cur {:notimeout true :slaveok true}) _ (add-options db-cur {:notimeout true :slaveok true})
opts (get-options db-cur)] opts (get-options db-cur)]
(is (= true (:notimeout opts))) (is (= true (:notimeout opts)))
@ -68,8 +67,8 @@
(is (= false (:tailable opts))) (is (= false (:tailable opts)))
(is (= false (:oplogreplay opts))))) (is (= false (:oplogreplay opts)))))
(deftest add-options-with-hashmap-and-remove-option (deftest add-options-with-hashmap-and-remove-option
(let [db-cur (make-db-cursor :docs) (let [db-cur (make-db-cursor db :docs)
_ (add-options db-cur {:notimeout true :slaveok true}) _ (add-options db-cur {:notimeout true :slaveok true})
opts (get-options db-cur)] opts (get-options db-cur)]
(is (= true (:notimeout opts))) (is (= true (:notimeout opts)))
@ -82,8 +81,8 @@
(is (= false (:slaveok opts))) (is (= false (:slaveok opts)))
(is (= false (:tailable opts)))))) (is (= false (:tailable opts))))))
(deftest add-options-with-list (deftest add-options-with-list
(let [db-cur (make-db-cursor :docs) (let [db-cur (make-db-cursor db :docs)
_ (add-options db-cur [:notimeout :slaveok]) _ (add-options db-cur [:notimeout :slaveok])
opts (get-options db-cur)] opts (get-options db-cur)]
(is (= true (:notimeout opts))) (is (= true (:notimeout opts)))
@ -91,8 +90,8 @@
(is (= false (:tailable opts))) (is (= false (:tailable opts)))
(is (= false (:oplogreplay opts))))) (is (= false (:oplogreplay opts)))))
(deftest add-options-with-Bytes (deftest add-options-with-Bytes
(let [db-cur (make-db-cursor :docs) (let [db-cur (make-db-cursor db :docs)
_ (add-options db-cur Bytes/QUERYOPTION_NOTIMEOUT) _ (add-options db-cur Bytes/QUERYOPTION_NOTIMEOUT)
opts (get-options db-cur)] opts (get-options db-cur)]
(is (= true (:notimeout opts))) (is (= true (:notimeout opts)))
@ -100,11 +99,11 @@
(is (= false (:tailable opts))) (is (= false (:tailable opts)))
(is (= false (:oplogreplay opts))))) (is (= false (:oplogreplay opts)))))
(deftest add-options-with-one-keyword (deftest add-options-with-one-keyword
(let [db-cur (make-db-cursor :docs) (let [db-cur (make-db-cursor db :docs)
_ (add-options db-cur :notimeout) _ (add-options db-cur :notimeout)
opts (get-options db-cur)] opts (get-options db-cur)]
(is (= true (:notimeout opts))) (is (= true (:notimeout opts)))
(is (= false (:slaveok opts))) (is (= false (:slaveok opts)))
(is (= false (:tailable opts))) (is (= false (:tailable opts)))
(is (= false (:oplogreplay opts))))) (is (= false (:oplogreplay opts))))))