Skip to content

Commit

Permalink
Test that every query operator is defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jokimaki committed Oct 30, 2016
1 parent d0fc0ed commit a2bc59d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/monger/test/query_operators_test.clj
Expand Up @@ -3,10 +3,28 @@
[monger.collection :as mc]
[monger.js :as js]
[clojure.test :refer :all]
[monger.operators :refer :all]))
[clojure.set :refer [difference]]
[monger.operators :refer :all])
(:import [com.mongodb QueryOperators]))

;; (use-fixtures :each purge-people purge-docs purge-things purge-libraries)

(deftest every-query-operator-is-defined
(let [driver-query-operators (->> (.getDeclaredFields QueryOperators) (map #(.get % nil)) set)
monger-query-operators (->> (ns-publics 'monger.operators) (map (comp name first)) set)
; $within is deprecated and replaced by $geoWithin since v2.4.
; $uniqueDocs is deprecated since v2.6.
deprecated-query-operators #{"$within" "$uniqueDocs"}
; Query modifier operators that are deprecated in the mongo shell since v3.2
deprecated-meta-operators #{"$comment" "$explain" "$hint" "$maxScan"
"$maxTimeMS" "$max" "$min" "$orderby"
"$returnKey" "$showDiskLoc" "$snapshot" "$query"}
undefined-non-deprecated-operators (difference driver-query-operators
deprecated-query-operators
deprecated-meta-operators
monger-query-operators)]
(is (= #{} undefined-non-deprecated-operators))))

(let [conn (mg/connect)
db (mg/get-db conn "monger-test")]
(defn purge-collections
Expand Down

0 comments on commit a2bc59d

Please sign in to comment.