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
|
||||
|
||||
No changes yet.
|
||||
### monger.result/ok? now works on Clojure maps
|
||||
|
||||
`monger.result/ok?` has been implemented for Clojure maps.
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@
|
|||
:indexing :indexing
|
||||
:external :external
|
||||
:cache :cache
|
||||
:gridfs :gridfs
|
||||
:gridfs :gridfs
|
||||
:command :command
|
||||
:performance :performance
|
||||
;; as in, edge mongodb server
|
||||
:edge-features :edge-features
|
||||
|
|
|
|||
|
|
@ -8,10 +8,20 @@
|
|||
;; You must not remove this notice, or any other, from this software.
|
||||
|
||||
(ns monger.result
|
||||
(:import [com.mongodb DBObject WriteResult MapReduceOutput])
|
||||
(:import [com.mongodb DBObject WriteResult MapReduceOutput]
|
||||
clojure.lang.IPersistentMap)
|
||||
(:require monger.conversion))
|
||||
|
||||
|
||||
;;
|
||||
;; Implementation
|
||||
;;
|
||||
|
||||
(defn- okayish?
|
||||
[value]
|
||||
(contains? #{true "true" 1 1.0} value))
|
||||
|
||||
|
||||
;;
|
||||
;; API
|
||||
;;
|
||||
|
|
@ -25,7 +35,7 @@
|
|||
DBObject
|
||||
(ok?
|
||||
[^DBObject result]
|
||||
(.contains [true "true" 1 1.0] (.get result "ok")))
|
||||
(okayish? (.get result "ok")))
|
||||
(has-error?
|
||||
[^DBObject result]
|
||||
;; yes, this is exactly the logic MongoDB Java driver uses.
|
||||
|
|
@ -50,4 +60,10 @@
|
|||
MapReduceOutput
|
||||
(ok?
|
||||
[^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
|
||||
(:require [monger.command :as mcom]
|
||||
(:require [monger.core :as mg]
|
||||
[monger.command :as mcom]
|
||||
[monger.test.helper :as helper]
|
||||
[monger.collection :as mc])
|
||||
(:use clojure.test
|
||||
monger.result))
|
||||
[monger.result :only [ok?]]
|
||||
[monger.conversion :only [from-db-object]]))
|
||||
|
||||
(helper/connect!)
|
||||
|
||||
|
||||
(deftest test-db-stats
|
||||
(deftest ^{:command true} test-db-stats
|
||||
(let [stats (mcom/db-stats)]
|
||||
(is (ok? stats))
|
||||
(is (= "monger-test" (get stats "db")))))
|
||||
|
||||
(deftest test-collection-stats
|
||||
(deftest ^{:command true} test-collection-stats
|
||||
(let [collection "stat_test"
|
||||
_ (mc/insert collection {:name "Clojure"})
|
||||
check (mc/count collection)
|
||||
|
|
@ -22,20 +24,27 @@
|
|||
(is (= "monger-test.stat_test" (get stats "ns")))
|
||||
(is (= check (get stats "count")))))
|
||||
|
||||
(deftest test-reindex-collection
|
||||
(deftest ^{:command true} test-reindex-collection
|
||||
(let [_ (mc/insert "test" {:name "Clojure"})
|
||||
result (mcom/reindex-collection "test")]
|
||||
(is (ok? result))
|
||||
(is (get result "indexes"))))
|
||||
|
||||
(deftest test-server-status
|
||||
(deftest ^{:command true} test-server-status
|
||||
(let [status (mcom/server-status)]
|
||||
(is (ok? status))
|
||||
(is (not-empty status))
|
||||
(is (get status "serverUsed"))))
|
||||
|
||||
(deftest test-top
|
||||
(deftest ^{:command true} test-top
|
||||
(let [result (mcom/top)]
|
||||
(is (ok? result))
|
||||
(is (not-empty result))
|
||||
(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