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
64443a3b
Commit
64443a3b
authored
10 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
favor using logger instead of println.
parent
e933ec80
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
test/metabase/test_data/load.clj
+7
-6
7 additions, 6 deletions
test/metabase/test_data/load.clj
test/metabase/test_utils.clj
+2
-3
2 additions, 3 deletions
test/metabase/test_utils.clj
with
9 additions
and
9 deletions
test/metabase/test_data/load.clj
+
7
−
6
View file @
64443a3b
(
ns
metabase.test-data.load
"Functions for creating a test Database with some mock data."
(
:require
[
clojure.string
:as
s
]
[
clojure.tools.logging
:as
log
]
(
korma
[
core
:refer
:all
]
[
db
:refer
:all
])
[
metabase.db
:refer
:all
]
...
...
@@ -40,15 +41,15 @@
(
or
(
sel
:one
Database
:name
db-name
)
(
do
(
when-not
(
.exists
(
clojure.java.io/file
(
str
@
test-db-filename
".h2.db"
)))
; only create + populate the test DB file if needed
(
create-and-populate-tables
))
(
println
"Creating new metabase Database object..."
)
(
log/info
"Creating new metabase Database object..."
)
(
let
[
db
(
ins
Database
:organization_id
(
:id
(
test-org
))
:name
db-name
:engine
:h2
:details
{
:conn_str
@
test-db-connection-string
})]
(
println
"Syncing Tables..."
)
(
log/info
"Syncing Tables..."
)
(
sync/sync-tables
db
)
(
println
"Finished. Enjoy your test data <3"
)
(
log/info
"Finished. Enjoy your test data <3"
)
db
))))
...
...
@@ -75,7 +76,7 @@
(
binding
[
*test-db*
(
create-db
(
h2
{
:db
@
test-db-connection-string
:naming
{
:keys
s/lower-case
:fields
s/upper-case
}}))]
(
println
"CREATING H2 TEST DATABASE..."
)
(
log/info
"CREATING H2 TEST DATABASE..."
)
~@
body
)))
(
defn-
exec-sql
...
...
@@ -108,14 +109,14 @@
(
with-test-db
(
let
[
table-name
(
->
table-name
name
s/upper-case
)
fields-for-insert
(
->>
fields
(
map
first
))]
; get ordered field names of data e.g. (:name :last_login)
(
println
(
format
"CREATING TABLE \"%s\"..."
table-name
))
(
log/info
(
format
"CREATING TABLE \"%s\"..."
table-name
))
(
exec-sql
(
format
"DROP TABLE IF EXISTS \"%s\";"
table-name
)
(
format
"CREATE TABLE \"%s\" (%s, \"ID\" BIGINT AUTO_INCREMENT, PRIMARY KEY (\"ID\"));"
table-name
(
format-fields
fields
)))
(
->
(
create-entity
table-name
)
(
database
*test-db*
)
(
insert
(
values
(
map
(
partial
zipmap
fields-for-insert
)
; data rows look like [name last-login]
rows
))))
; need to convert to {:name name :last_login last-login} for insert
(
println
(
format
"Inserted %d rows."
(
count
rows
))))))
(
log/info
(
format
"Inserted %d rows."
(
count
rows
))))))
(
defn-
create-and-populate-tables
[]
(
with-test-db
...
...
This diff is collapsed.
Click to expand it.
test/metabase/test_utils.clj
+
2
−
3
View file @
64443a3b
...
...
@@ -29,7 +29,6 @@
[
".h2.db"
".trace.db"
".lock.db"
]))
; TODO - lets just completely delete the db before each test to ensure we start fresh
(
log/info
"tearing down database and resetting to empty schema"
)
(
migrate
(
setup-jdbc-db
)
:down
)
(
log/info
"setting up database and running all migrations"
)
...
...
@@ -44,13 +43,13 @@
(
try
(
ring/run-jetty
core/app
{
:port
3000
:join?
false
})
; detach the thread
(
catch
java.net.BindException
e
; assume server is already running if port's already bound
(
println
"ALREADY RUNNING!"
)))))
; e.g. if someone is running `lein ring server` locally. Tests should still work normally.
(
log/error
"ALREADY RUNNING!"
)))))
; e.g. if someone is running `lein ring server` locally. Tests should still work normally.
(
defn
start-jetty
"Start the Jetty web server."
{
:expectations-options
:before-run
}
[]
(
println
"STARTING THE JETTY SERVER..."
)
(
log/info
"STARTING THE JETTY SERVER..."
)
@
jetty-instance
)
(
defn
stop-jetty
...
...
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