Assert/spec/tests for empty cols in insert-multi!

This commit is contained in:
Sean Corfield 2019-07-11 12:52:36 -07:00
parent 4d7a5a440b
commit 4457161305
3 changed files with 10 additions and 2 deletions

View file

@ -126,8 +126,11 @@
(s/fdef sql/insert-multi!
:args (s/and (s/cat :connectable ::connectable
:table keyword?
:cols (s/coll-of keyword? :kind sequential?)
:rows (s/coll-of (s/coll-of any? :kind sequential?) :kind sequential?)
:cols (s/coll-of keyword?
:kind sequential?
:min-count 1)
:rows (s/coll-of (s/coll-of any? :kind sequential?)
:kind sequential?)
:opts (s/? ::opts-map))
#(apply = (count (:cols %))
(map count (:rows %)))))

View file

@ -165,6 +165,7 @@
(assert (apply = (count cols) (map count rows))
"column counts are not consistent across cols and rows")
;; to avoid generating bad SQL
(assert (seq cols) "cols may not be empty")
(assert (seq rows) "rows may not be empty")
(let [table-fn (:table-fn opts identity)
column-fn (:column-fn opts identity)

View file

@ -187,6 +187,10 @@
(is (thrown? clojure.lang.ExceptionInfo
(sql/delete! (ds) :fruit {}))))
(deftest no-empty-columns
(is (thrown? clojure.lang.ExceptionInfo
(sql/insert-multi! (ds) :fruit [] [[] [] []]))))
(deftest no-empty-order-by
(is (thrown? clojure.lang.ExceptionInfo
(sql/find-by-keys (ds) :fruit