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

DO NOT RUN TESTS ON SHUTDOWN! EVER!

parent 211f883e
Branches
Tags
No related merge requests found
......@@ -94,3 +94,14 @@
with database connections so admins can identify them as Metabase ones.
Looks something like `Metabase v0.25.0.RC1`."
(str "Metabase " (mb-version-info :tag)))
;; This only affects dev:
;;
;; If for some wacky reason the test namespaces are getting loaded (e.g. when running via
;; `lein ring` or `lein ring sever`, DO NOT RUN THE EXPECTATIONS TESTS AT SHUTDOWN! THIS WILL NUKE YOUR APPLICATION DB
(try
(require 'expectations)
((resolve 'expectations/disable-run-on-shutdown))
;; This will fail if the test dependencies aren't present (e.g. in a JAR situation) which is totally fine
(catch Throwable _))
......@@ -12,12 +12,13 @@
[toucan.util.test :as tt])
(:import metabase.models.permissions_group.PermissionsGroupInstance))
;;; ---------------------------------------- Check that the root entry for Admin was created ----------------------------------------
;;; -------------------------------- Check that the root entry for Admin was created ---------------------------------
(expect (db/exists? Permissions :group_id (:id (perm-group/admin)), :object "/"))
;;; ---------------------------------------- check that we can get the magic permissions groups through the helper functions ----------------------------------------
;;; ---------------- check that we can get the magic permissions groups through the helper functions -----------------
(expect PermissionsGroupInstance (perm-group/all-users))
(expect PermissionsGroupInstance (perm-group/admin))
(expect PermissionsGroupInstance (perm-group/metabot))
......@@ -39,7 +40,8 @@
(expect Exception (db/update! PermissionsGroup (:id (perm-group/metabot)) :name "Cool People"))
;;; ---------------------------------------- newly created users should get added to the appropriate magic groups ----------------------------------------
;;; ---------------------- newly created users should get added to the appropriate magic groups ----------------------
(expect
(tt/with-temp User [{user-id :id}]
(db/exists? PermissionsGroupMembership
......@@ -62,7 +64,8 @@
(expect
(do
;; make sure Crowberto is in the DB because otherwise the code will get snippy when the temp user is deleted since you're not allowed to delete the last member of Admin
;; make sure Crowberto is in the DB because otherwise the code will get snippy when the temp user is deleted since
;; you're not allowed to delete the last member of Admin
(test-users/user->id :crowberto)
(tt/with-temp User [{user-id :id} {:is_superuser true}]
(db/exists? PermissionsGroupMembership
......@@ -76,7 +79,7 @@
:group_id (:id (perm-group/admin)))))
;;; ---------------------------------------- magic groups should have permissions for newly created databases ----------------------------------------
;;; ------------------------ magic groups should have permissions for newly created databases ------------------------
(defn- group-has-full-access?
"Does a group have permissions for OBJECT and *all* of its children?"
......@@ -100,8 +103,8 @@
(group-has-full-access? (:id (perm-group/metabot)) (perms/object-path database-id))))
;;; -------------- flipping the is_superuser bit should add/remove user from Admin group as appropriate --------------
;;; ---------------------------------------- flipping the is_superuser bit should add/remove user from Admin group as appropriate ----------------------------------------
;; adding user to Admin should set is_superuser -> true
(expect
(tt/with-temp User [{user-id :id}]
......
(ns metabase.test-setup
"Functions that run before + after unit tests (setup DB, start web server, load test data)."
(:require [clojure data
(:require [clojure
[data :as data]
[set :as set]]
[clojure.tools.logging :as log]
[expectations :refer :all]
......@@ -14,12 +15,6 @@
;;; ---------------------------------------- Expectations Framework Settings -----------------------------------------
;; ## GENERAL SETTINGS
;; Don't run unit tests whenever JVM shuts down
(expectations/disable-run-on-shutdown)
;; ## EXPECTATIONS FORMATTING OVERRIDES
;; These overrides the methods Expectations usually uses for printing failed tests.
......@@ -28,9 +23,9 @@
;; lot of data, like Query Processor or API tests.
(defn- format-failure [e a str-e str-a]
{:type :fail
:expected-message (when-let [in-e (first (clojure.data/diff e a))]
:expected-message (when-let [in-e (first (data/diff e a))]
(format "\nin expected, not actual:\n%s" (u/pprint-to-str 'green in-e)))
:actual-message (when-let [in-a (first (clojure.data/diff a e))]
:actual-message (when-let [in-a (first (data/diff a e))]
(format "\nin actual, not expected:\n%s" (u/pprint-to-str 'red in-a)))
:raw [str-e str-a]
:result ["\nexpected:\n"
......@@ -39,7 +34,7 @@
(u/pprint-to-str 'red a)]})
(defmethod compare-expr :expectations/maps [e a str-e str-a]
(let [[in-e in-a] (clojure.data/diff e a)]
(let [[in-e in-a] (data/diff e a)]
(if (and (nil? in-e) (nil? in-a))
{:type :pass}
(format-failure e a str-e str-a))))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment