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
4e6bd7c3
Commit
4e6bd7c3
authored
7 years ago
by
Simon Belak
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:metabase/metabase into xray-insights-batch1
parents
98aa5bc3
914255b5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
project.clj
+6
-5
6 additions, 5 deletions
project.clj
test/expectation_options.clj
+43
-0
43 additions, 0 deletions
test/expectation_options.clj
test/metabase/test/util.clj
+11
-0
11 additions, 0 deletions
test/metabase/test/util.clj
with
60 additions
and
5 deletions
project.clj
+
6
−
5
View file @
4e6bd7c3
...
...
@@ -121,7 +121,8 @@
:uberjar-name
"metabase.jar"
:ring
{
:handler
metabase.core/app
:init
metabase.core/init!
:destroy
metabase.core/destroy
}
:destroy
metabase.core/destroy
:reload-paths
[
"src"
]}
:eastwood
{
:exclude-namespaces
[
:test-paths
metabase.driver.generic-sql
]
; ISQLDriver causes Eastwood to fail. Skip this ns until issue is fixed: https://github.com/jonase/eastwood/issues/191
:add-linters
[
:unused-private-vars
...
...
@@ -147,16 +148,16 @@
:exclusions
[
org.clojure/clojure
org.clojure/tools.namespace
]]]
:env
{
:mb-run-mode
"dev"
}
:jvm-opts
[
"-Dlogfile.path=target/log"
"-Xms1024m"
; give JVM a decent heap size to start with
"-Xmx2048m"
]
; hard limit of 2GB so we stop hitting the 4GB container limit on CircleCI
:jvm-opts
[
"-Dlogfile.path=target/log"
]
:aot
[
metabase.logger
]}
; Log appender class needs to be compiled for log4j to use it
:reflection-warnings
{
:global-vars
{
*warn-on-reflection*
true
}}
; run `lein check-reflection-warnings` to check for reflection warnings
:expectations
{
:injections
[(
require
'metabase.test-setup
)]
:resource-paths
[
"test_resources"
]
:env
{
:mb-test-setting-1
"ABCDEFG"
:mb-run-mode
"test"
}
:jvm-opts
[
"-Duser.timezone=UTC"
:jvm-opts
[
"-Xms1024m"
; give JVM a decent heap size to start with
"-Xmx2048m"
; hard limit of 2GB so we stop hitting the 4GB container limit on CircleCI
"-Duser.timezone=UTC"
"-Dmb.db.in.memory=true"
"-Dmb.jetty.join=false"
"-Dmb.jetty.port=3010"
...
...
This diff is collapsed.
Click to expand it.
test/expectation_options.clj
0 → 100644
+
43
−
0
View file @
4e6bd7c3
(
ns
expectation-options
"Namspace expectations will automatically load before running a tests"
)
(
defn-
tables-with-data->error-msg
"Function that takes a list of modes and whill query each. If records are found, return a string with an error
message"
[
models-to-check
]
(
for
[
model
models-to-check
:let
[
instances-found
(
count
(
model
))
more-than-one?
(
>
1
instances-found
)]
:when
(
<
0
instances-found
)]
(
str
"Found '"
instances-found
"' instance"
(
when
more-than-one?
"s"
)
" of '"
(
:name
model
)
"' that "
(
if
more-than-one?
"were"
"was"
)
" not cleaned up."
)))
(
def
^
:private
models-to-check
"Add models from `metabase.models.*` to the following vector to have the `check-table-cleanup` function below error
if any instances of that model are found after each test finishes."
[])
(
defn
check-table-cleanup
"Function that will run around each test. This function is usually a noop, but it useful for helping to debug stale
data in local development. Modify the private `models-to-check` var to check if there are any rows in the given
model's table after each expectation. If a row is found, the relevant information will be written to standard out
and the test run will exit"
{
:expectations-options
:in-context
}
[
test-fn
]
(
let
[
result
(
test-fn
)]
;; The typical case is no models-to-check, this then becomes a noop
(
when
(
seq
models-to-check
)
(
let
[{
:keys
[
file
line
]}
(
->
test-fn
meta
:the-var
meta
)
error-msgs
(
tables-with-data->error-msg
models-to-check
)]
(
when
(
seq
error-msgs
)
(
println
"\n-----------------------------------------------------"
)
(
doseq
[
error-msg
error-msgs
]
(
println
error-msg
))
(
println
"-----------------------------------------------------"
)
(
printf
"\nStale test rows found in tables, check '%s' at line '%s'\n\n"
file
line
)
(
flush
)
;; I found this necessary as throwing an exception would show the exception, but the test run would hang and
;; you'd have to Ctrl-C anyway
(
System/exit
1
))))
result
))
This diff is collapsed.
Click to expand it.
test/metabase/test/util.clj
+
11
−
0
View file @
4e6bd7c3
...
...
@@ -28,6 +28,7 @@
[
user
:refer
[
User
]]]
[
metabase.test.data
:as
data
]
[
metabase.test.data.datasets
:refer
[
*driver*
]]
[
toucan.db
:as
db
]
[
toucan.util.test
:as
test
])
(
:import
java.util.TimeZone
[
org.joda.time
DateTime
DateTimeZone
]
...
...
@@ -451,3 +452,13 @@
"Invokes `BODY` with the JVM timezone set to `DTZ`"
[
dtz
&
body
]
`
(
call-with-jvm-tz
~
dtz
(
fn
[]
~@
body
)))
(
defmacro
with-model-cleanup
"This will delete all rows found for each model in `MODEL-SEQ`. This calls `delete!`, so if the model has defined
any `pre-delete` behavior, that will be preserved."
[
model-seq
&
body
]
`
(
try
~@
body
(
finally
(
doseq
[
model
#
~
model-seq
]
(
db/delete!
model
#
)))))
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