Back

validate-options (clj)

(source)

function

(validate-options options)
Validate `options`

Examples

hikari-cp
(ns hikari-cp.core-test
  (:require [hikari-cp.core :refer :all])
  (:use expectations)
  (:import (com.zaxxer.hikari.pool HikariPool$PoolInitializationException)
           (com.codahale.metrics MetricRegistry)
           (com.codahale.metrics.health HealthCheckRegistry)
           (com.zaxxer.hikari.metrics.prometheus PrometheusMetricsTrackerFactory)))

(expect IllegalArgumentException
        (datasource-config (dissoc valid-options :adapter)))
(expect #"contains\? % :adapter"
        (try
          (datasource-config (validate-options (dissoc valid-options :adapter)))
          (catch IllegalArgumentException e
            (str (.getMessage e)))))

(expect map?
        (validate-options valid-options))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:auto-commit 1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:read-only 1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:connection-timeout "foo"})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:connection-timeout 999})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:validation-timeout 999})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:idle-timeout -1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:max-lifetime -1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:minimum-idle -1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:maximum-pool-size -1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:maximum-pool-size 0})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:adapter :foo})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:datasource-classname "adsf"})))
(expect IllegalArgumentException
        (validate-options (merge (dissoc valid-options :adapter) {:jdbc-url nil})))
(expect IllegalArgumentException
        (validate-options (merge (dissoc valid-options :adapter) {:jdbc-url "jdbc:h2:~/test"
                                                                  :driver-class-name nil})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:transaction-isolation 1})))

(expect map?
        (validate-options (merge valid-options {:username nil})))
(expect map?
        (validate-options (dissoc valid-options :username)))
(expect map?
        (validate-options (dissoc valid-options :password)))
(expect map?
        (validate-options (merge valid-options {:password nil})))
(expect map?
        (validate-options (merge valid-options {:database-name nil})))
(expect map?
        (validate-options (dissoc valid-options :database-name)))
(expect map?
        (validate-options (dissoc valid-options :server-name)))
(expect map?
        (validate-options (merge valid-options {:server-name nil})))
(expect map?
        (validate-options (merge valid-options {:port-number -1})))
(expect map?
        (validate-options (dissoc valid-options :port-number)))
(expect map?
        (validate-options (merge (dissoc valid-options :adapter) {:jdbc-url "jdbc:h2:~/test"})))
(expect map?
        (validate-options (merge (dissoc valid-options :adapter) {:jdbc-url "jdbc:h2:~/test"
                                                                  :driver-class-name "org.h2.Driver"})))

;; it should complain, that value is too small
(expect IllegalArgumentException
  (validate-options (assoc valid-options :leak-detection-threshold 1)))
(expect IllegalArgumentException
  (validate-options (assoc valid-options :leak-detection-threshold 1999)))
tomekw/hikari-cp
(ns hikari-cp.core-test
  (:require [hikari-cp.core :refer :all])
  (:use expectations)
  (:import (com.zaxxer.hikari.pool HikariPool$PoolInitializationException)
           (com.codahale.metrics MetricRegistry)
           (com.codahale.metrics.health HealthCheckRegistry)
           (com.zaxxer.hikari.metrics.prometheus PrometheusMetricsTrackerFactory)))

(expect IllegalArgumentException
        (datasource-config (dissoc valid-options :adapter)))
(expect #"contains\? % :adapter"
        (try
          (datasource-config (validate-options (dissoc valid-options :adapter)))
          (catch IllegalArgumentException e
            (str (.getMessage e)))))

(expect map?
        (validate-options valid-options))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:auto-commit 1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:read-only 1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:connection-timeout "foo"})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:connection-timeout 999})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:validation-timeout 999})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:idle-timeout -1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:max-lifetime -1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:minimum-idle -1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:maximum-pool-size -1})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:maximum-pool-size 0})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:adapter :foo})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:datasource-classname "adsf"})))
(expect IllegalArgumentException
        (validate-options (merge (dissoc valid-options :adapter) {:jdbc-url nil})))
(expect IllegalArgumentException
        (validate-options (merge (dissoc valid-options :adapter) {:jdbc-url "jdbc:h2:~/test"
                                                                  :driver-class-name nil})))
(expect IllegalArgumentException
        (validate-options (merge valid-options {:transaction-isolation 1})))

(expect map?
        (validate-options (merge valid-options {:username nil})))
(expect map?
        (validate-options (dissoc valid-options :username)))
(expect map?
        (validate-options (dissoc valid-options :password)))
(expect map?
        (validate-options (merge valid-options {:password nil})))
(expect map?
        (validate-options (merge valid-options {:database-name nil})))
(expect map?
        (validate-options (dissoc valid-options :database-name)))
(expect map?
        (validate-options (dissoc valid-options :server-name)))
(expect map?
        (validate-options (merge valid-options {:server-name nil})))
(expect map?
        (validate-options (merge valid-options {:port-number -1})))
(expect map?
        (validate-options (dissoc valid-options :port-number)))
(expect map?
        (validate-options (merge (dissoc valid-options :adapter) {:jdbc-url "jdbc:h2:~/test"})))
(expect map?
        (validate-options (merge (dissoc valid-options :adapter) {:jdbc-url "jdbc:h2:~/test"
                                                                  :driver-class-name "org.h2.Driver"})))

;; it should complain, that value is too small
(expect IllegalArgumentException
  (validate-options (assoc valid-options :leak-detection-threshold 1)))
(expect IllegalArgumentException
  (validate-options (assoc valid-options :leak-detection-threshold 1999)))