Skip to content
Snippets Groups Projects
Unverified Commit 410b5dd3 authored by Cam Saul's avatar Cam Saul
Browse files

Tests for new defsetting options

parent c2c4e2d7
No related branches found
No related tags found
No related merge requests found
......@@ -49,6 +49,10 @@
(test-setting-2 setting-2-value))
(expect
String
(:tag (meta #'test-setting-1)))
;; ## GETTERS
;; Test defsetting getter fn. Should return the value from env var MB_TEST_SETTING_1
(expect "ABCDEFG"
......@@ -219,6 +223,10 @@
;;; ------------------------------------------------ BOOLEAN SETTINGS ------------------------------------------------
(expect
Boolean
(:tag (meta #'test-boolean-setting)))
(expect
{:value nil, :is_env_setting false, :env_name "MB_TEST_BOOLEAN_SETTING", :default nil}
(user-facing-info-with-db-and-env-var-values :test-boolean-setting nil nil))
......@@ -293,6 +301,10 @@
;; ok, make sure the setting was set
(toucan-name)))
(expect
String
(:tag (meta #'toucan-name)))
;;; ----------------------------------------------- Encrypted Settings -----------------------------------------------
......@@ -323,6 +335,23 @@
(actual-value-in-db :toucan-name)))
;;; ----------------------------------------------- TIMESTAMP SETTINGS -----------------------------------------------
(defsetting ^:private test-timestamp-setting
"Test timestamp setting"
:type :timestamp)
(expect
java.sql.Timestamp
(:tag (meta #'test-timestamp-setting)))
;; make sure we can set & fetch the value and that it gets serialized/deserialized correctly
(expect
#inst "2018-07-11T09:32:00.000Z"
(do (test-timestamp-setting #inst "2018-07-11T09:32:00.000Z")
(test-timestamp-setting)))
;;; --------------------------------------------- Cache Synchronization ----------------------------------------------
(def ^:private settings-last-updated-key @(resolve 'metabase.models.setting/settings-last-updated-key))
......@@ -444,3 +473,34 @@
;; detect a cache out-of-date situation and flush the cache as appropriate, giving us the updated value when we
;; call! :wow:
(toucan-name)))
;;; ----------------------------------------------- Uncached Settings ------------------------------------------------
(defsetting ^:private uncached-setting
"A test setting that should *not* be cached."
:cache? false)
;; make sure uncached setting still saves to the DB
(expect
"ABCDEF"
(encryption-test/with-secret-key nil
(uncached-setting "ABCDEF")
(actual-value-in-db "uncached-setting")))
;; make sure that fetching the Setting always fetches the latest value from the DB
(expect
"123456"
(encryption-test/with-secret-key nil
(uncached-setting "ABCDEF")
(db/update-where! Setting {:key "uncached-setting"}
:value "123456")
(uncached-setting)))
;; make sure that updating the setting doesn't update the last-updated timestamp in the cache $$
(expect
nil
(encryption-test/with-secret-key nil
(clear-settings-last-updated-value-in-db!)
(uncached-setting "abcdef")
(settings-last-updated-value-in-db)))
......@@ -37,7 +37,8 @@
[dataset-definitions :as defs]]
[toucan.db :as db]
[toucan.util.test :as test])
(:import java.util.TimeZone
(:import com.mchange.v2.c3p0.PooledDataSource
java.util.TimeZone
org.joda.time.DateTimeZone
[org.quartz CronTrigger JobDetail JobKey Scheduler Trigger]))
......@@ -451,7 +452,7 @@
timezone. That causes problems for tests that we can determine the database's timezone. This function will reset the
connections in the connection pool for `db` to ensure that we get fresh session with no timezone specified"
[db]
(when-let [conn-pool (:datasource (sql/db->pooled-connection-spec db))]
(when-let [^PooledDataSource conn-pool (:datasource (sql/db->pooled-connection-spec db))]
(.softResetAllUsers conn-pool)))
(defn db-timezone-id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment