Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
32d65b34
Commit
32d65b34
authored
9 years ago
by
Cam Saul
Browse files
Options
Downloads
Patches
Plain Diff
MB_TEST_AGAINST_DRIVERS can be used to run QP unit tests against a
subset of drivers
parent
53e2ba01
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/metabase/driver/query_processor_test.clj
+49
-6
49 additions, 6 deletions
test/metabase/driver/query_processor_test.clj
with
49 additions
and
6 deletions
test/metabase/driver/query_processor_test.clj
+
49
−
6
View file @
32d65b34
(
ns
metabase.driver.query-processor-test
"Query processing tests that can be ran between any of the available drivers, and should give the same results."
(
:require
[
expectations
:refer
:all
]
(
:require
[
clojure.string
:as
s
]
[
clojure.tools.logging
:as
log
]
[
colorize.core
:as
color
]
[
environ.core
:refer
[
env
]]
[
expectations
:refer
:all
]
[
metabase.db
:refer
:all
]
[
metabase.driver
:as
driver
]
[
metabase.driver.mongo.test-data
:as
mongo-data
]
...
...
@@ -15,6 +19,8 @@
"Bound to ID of `Database` for the current driver inside body of `with-driver`."
)
(
def
^
:dynamic
*driver-dataset*
)
;; ### IDriverDataset + Implementations
(
defprotocol
IDriverDataset
"Functions needed to fetch test data for various drivers."
(
db
[
this
]
...
...
@@ -69,15 +75,52 @@
{
:mongo
(
MongoDriverData.
)
:generic-sql
(
GenericSqlDriverData.
)})
(
def
valid-driver-names
"
Set of valid driver name keywords
."
(
def
all-
valid-driver-names
"
Names of all valid drivers to test against
."
(
set
(
keys
driver-name->driver-dataset
)))
;; ### Logic for determining which drivers to test against
;; By default, we'll test against *all* valid drivers;
;; otherwise, you can test against only a subset of drivers by setting the env var `MB_TEST_AGAINST_DRIVERS`
;; to a comma-separated list of driver names, e.g.
;;
;; # test against :generic-sql and :mongo
;; MB_TEST_AGAINST_DRIVERS=generic-sql,mongo
;;
;; # just test against :generic-sql
;; MB_TEST_AGAINST_DRIVERS=generic-sql
(
defn-
get-drivers-to-test-from-env
"Return a set of driver names to test against from the env var `MB_TEST_AGAINST_DRIVERS`."
[]
(
when-let
[
env-drivers
(
some->
(
env
:mb-test-against-drivers
)
s/lower-case
)]
(
->>
(
s/split
env-drivers
#
","
)
(
map
keyword
)
;; Double check that the specified drivers are all valid
(
map
(
fn
[
driver-name
]
(
assert
(
contains?
all-valid-driver-names
driver-name
)
(
format
"Invalid driver specified in MB_TEST_AGAINST_DRIVERS: %s"
(
name
driver-name
)))
driver-name
))
set
)))
(
def
driver-names-to-test
"Delay that returns set of names of drivers we should run tests against.
By default, this returns *all* drivers, but can be overriden by setting env var `MB_TEST_AGAINST_DRIVERS`."
(
delay
(
let
[
drivers
(
or
(
get-drivers-to-test-from-env
)
all-valid-driver-names
)]
(
log/info
(
color/green
"Running QP tests against these drivers: "
drivers
))
drivers
)))
;; ### EXPECT-WITH-ALL-DRIVERS
(
defmacro
with-driver
"Execute BODY with `*db*` and `*db-id*` bound to appropriate
plac
es for "
"Execute BODY with
`*driver-dataset*`,
`*db*` and `*db-id*` bound to appropriate
valu
es for
DRIVER-NAME.
"
[
driver-name
&
body
]
{
:pre
[(
keyword?
driver-name
)
(
contains?
valid-driver-names
driver-name
)]}
(
contains?
all-
valid-driver-names
driver-name
)]}
`
(
let
[
driver-data
#
(
driver-name->driver-dataset
~
driver-name
)
db
#
(
db
driver-data
#
)]
(
binding
[
*driver-dataset*
driver-data
#
...
...
@@ -96,7 +139,7 @@
~
expected
)
(
with-driver
~
driver-name
~
actual
))])
valid-
driver-names
)))
@
driver-names
-to-test
)))
;; ## Driver-Independent Data Fns
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment