Implement monger.result/ok? for Clojure maps
This commit is contained in:
parent
77281ba466
commit
babd429f5b
4 changed files with 40 additions and 12 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
## Changes between 1.0.0-beta8 and 1.0.0-rc1
|
## Changes between 1.0.0-beta8 and 1.0.0-rc1
|
||||||
|
|
||||||
No changes yet.
|
### monger.result/ok? now works on Clojure maps
|
||||||
|
|
||||||
|
`monger.result/ok?` has been implemented for Clojure maps.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
:external :external
|
:external :external
|
||||||
:cache :cache
|
:cache :cache
|
||||||
:gridfs :gridfs
|
:gridfs :gridfs
|
||||||
|
:command :command
|
||||||
:performance :performance
|
:performance :performance
|
||||||
;; as in, edge mongodb server
|
;; as in, edge mongodb server
|
||||||
:edge-features :edge-features
|
:edge-features :edge-features
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,20 @@
|
||||||
;; You must not remove this notice, or any other, from this software.
|
;; You must not remove this notice, or any other, from this software.
|
||||||
|
|
||||||
(ns monger.result
|
(ns monger.result
|
||||||
(:import [com.mongodb DBObject WriteResult MapReduceOutput])
|
(:import [com.mongodb DBObject WriteResult MapReduceOutput]
|
||||||
|
clojure.lang.IPersistentMap)
|
||||||
(:require monger.conversion))
|
(:require monger.conversion))
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;; Implementation
|
||||||
|
;;
|
||||||
|
|
||||||
|
(defn- okayish?
|
||||||
|
[value]
|
||||||
|
(contains? #{true "true" 1 1.0} value))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; API
|
;; API
|
||||||
;;
|
;;
|
||||||
|
|
@ -25,7 +35,7 @@
|
||||||
DBObject
|
DBObject
|
||||||
(ok?
|
(ok?
|
||||||
[^DBObject result]
|
[^DBObject result]
|
||||||
(.contains [true "true" 1 1.0] (.get result "ok")))
|
(okayish? (.get result "ok")))
|
||||||
(has-error?
|
(has-error?
|
||||||
[^DBObject result]
|
[^DBObject result]
|
||||||
;; yes, this is exactly the logic MongoDB Java driver uses.
|
;; yes, this is exactly the logic MongoDB Java driver uses.
|
||||||
|
|
@ -50,4 +60,10 @@
|
||||||
MapReduceOutput
|
MapReduceOutput
|
||||||
(ok?
|
(ok?
|
||||||
[^MapReduceOutput result]
|
[^MapReduceOutput result]
|
||||||
(ok? ^DBObject (.getRaw result))))
|
(ok? ^DBObject (.getRaw result)))
|
||||||
|
|
||||||
|
IPersistentMap
|
||||||
|
(ok?
|
||||||
|
[^IPersistentMap m]
|
||||||
|
(okayish? (or (get m :ok)
|
||||||
|
(get m "ok")))))
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,21 @@
|
||||||
(ns monger.test.command-test
|
(ns monger.test.command-test
|
||||||
(:require [monger.command :as mcom]
|
(:require [monger.core :as mg]
|
||||||
|
[monger.command :as mcom]
|
||||||
[monger.test.helper :as helper]
|
[monger.test.helper :as helper]
|
||||||
[monger.collection :as mc])
|
[monger.collection :as mc])
|
||||||
(:use clojure.test
|
(:use clojure.test
|
||||||
monger.result))
|
[monger.result :only [ok?]]
|
||||||
|
[monger.conversion :only [from-db-object]]))
|
||||||
|
|
||||||
(helper/connect!)
|
(helper/connect!)
|
||||||
|
|
||||||
|
|
||||||
(deftest test-db-stats
|
(deftest ^{:command true} test-db-stats
|
||||||
(let [stats (mcom/db-stats)]
|
(let [stats (mcom/db-stats)]
|
||||||
(is (ok? stats))
|
(is (ok? stats))
|
||||||
(is (= "monger-test" (get stats "db")))))
|
(is (= "monger-test" (get stats "db")))))
|
||||||
|
|
||||||
(deftest test-collection-stats
|
(deftest ^{:command true} test-collection-stats
|
||||||
(let [collection "stat_test"
|
(let [collection "stat_test"
|
||||||
_ (mc/insert collection {:name "Clojure"})
|
_ (mc/insert collection {:name "Clojure"})
|
||||||
check (mc/count collection)
|
check (mc/count collection)
|
||||||
|
|
@ -22,20 +24,27 @@
|
||||||
(is (= "monger-test.stat_test" (get stats "ns")))
|
(is (= "monger-test.stat_test" (get stats "ns")))
|
||||||
(is (= check (get stats "count")))))
|
(is (= check (get stats "count")))))
|
||||||
|
|
||||||
(deftest test-reindex-collection
|
(deftest ^{:command true} test-reindex-collection
|
||||||
(let [_ (mc/insert "test" {:name "Clojure"})
|
(let [_ (mc/insert "test" {:name "Clojure"})
|
||||||
result (mcom/reindex-collection "test")]
|
result (mcom/reindex-collection "test")]
|
||||||
(is (ok? result))
|
(is (ok? result))
|
||||||
(is (get result "indexes"))))
|
(is (get result "indexes"))))
|
||||||
|
|
||||||
(deftest test-server-status
|
(deftest ^{:command true} test-server-status
|
||||||
(let [status (mcom/server-status)]
|
(let [status (mcom/server-status)]
|
||||||
(is (ok? status))
|
(is (ok? status))
|
||||||
(is (not-empty status))
|
(is (not-empty status))
|
||||||
(is (get status "serverUsed"))))
|
(is (get status "serverUsed"))))
|
||||||
|
|
||||||
(deftest test-top
|
(deftest ^{:command true} test-top
|
||||||
(let [result (mcom/top)]
|
(let [result (mcom/top)]
|
||||||
(is (ok? result))
|
(is (ok? result))
|
||||||
(is (not-empty result))
|
(is (not-empty result))
|
||||||
(is (get result "serverUsed"))))
|
(is (get result "serverUsed"))))
|
||||||
|
|
||||||
|
(deftest ^{:command true} test-running-is-master-as-an-arbitrary-command
|
||||||
|
(let [raw (mg/command {:isMaster 1})
|
||||||
|
result (from-db-object raw true)]
|
||||||
|
(is (ok? result))
|
||||||
|
(is (ok? raw))
|
||||||
|
(is (:ismaster result))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue