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
7a57fae0
Commit
7a57fae0
authored
9 years ago
by
Allen Gilliland
Browse files
Options
Downloads
Patches
Plain Diff
couple fixes for unit testing.
parent
f3c3667b
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
src/metabase/api/database.clj
+15
-14
15 additions, 14 deletions
src/metabase/api/database.clj
test/metabase/api/database_test.clj
+7
-12
7 additions, 12 deletions
test/metabase/api/database_test.clj
with
22 additions
and
26 deletions
src/metabase/api/database.clj
+
15
−
14
View file @
7a57fae0
...
@@ -22,20 +22,21 @@
...
@@ -22,20 +22,21 @@
(
defn
test-database-connection
(
defn
test-database-connection
"Try out the connection details for a database and useful error message if connection fails, returns `nil` if connection succeeds."
"Try out the connection details for a database and useful error message if connection fails, returns `nil` if connection succeeds."
[
engine
{
:keys
[
host
port
]
:as
details
}]
[
engine
{
:keys
[
host
port
]
:as
details
}]
(
let
[
engine
(
keyword
engine
)
(
when
(
not
(
metabase.config/is-test?
))
details
(
assoc
details
:engine
engine
)
(
let
[
engine
(
keyword
engine
)
response-invalid
(
fn
[
field
m
]
{
:valid
false
details
(
assoc
details
:engine
engine
)
field
m
; work with the new {:field error-message} format
response-invalid
(
fn
[
field
m
]
{
:valid
false
:message
m
})]
; but be backwards-compatible with the UI as it exists right now
field
m
; work with the new {:field error-message} format
(
try
:message
m
})]
; but be backwards-compatible with the UI as it exists right now
(
cond
(
try
(
driver/can-connect-with-details?
engine
details
:rethrow-exceptions
)
nil
(
cond
(
and
host
port
(
u/host-port-up?
host
port
))
(
response-invalid
:dbname
(
format
"Connection to '%s:%d' successful, but could not connect to DB."
host
port
))
(
driver/can-connect-with-details?
engine
details
:rethrow-exceptions
)
nil
(
and
host
(
u/host-up?
host
))
(
response-invalid
:port
(
format
"Connection to '%s' successful, but port %d is invalid."
port
))
(
and
host
port
(
u/host-port-up?
host
port
))
(
response-invalid
:dbname
(
format
"Connection to '%s:%d' successful, but could not connect to DB."
host
port
))
host
(
response-invalid
:host
(
format
"'%s' is not reachable"
host
))
(
and
host
(
u/host-up?
host
))
(
response-invalid
:port
(
format
"Connection to '%s' successful, but port %d is invalid."
port
))
:else
(
response-invalid
:db
"Unable to connect to database."
))
host
(
response-invalid
:host
(
format
"'%s' is not reachable"
host
))
(
catch
Throwable
e
:else
(
response-invalid
:db
"Unable to connect to database."
))
(
response-invalid
:dbname
(
.getMessage
e
))))))
(
catch
Throwable
e
(
response-invalid
:dbname
(
.getMessage
e
)))))))
(
defn
supports-ssl?
(
defn
supports-ssl?
"Predicate function which determines if a given `engine` supports the `:ssl` setting."
"Predicate function which determines if a given `engine` supports the `:ssl` setting."
...
...
This diff is collapsed.
Click to expand it.
test/metabase/api/database_test.clj
+
7
−
12
View file @
7a57fae0
...
@@ -19,7 +19,8 @@
...
@@ -19,7 +19,8 @@
:details
{
:host
"localhost"
:details
{
:host
"localhost"
:port
5432
:port
5432
:dbname
"fakedb"
:dbname
"fakedb"
:user
"cam"
}}))
:user
"cam"
:ssl
false
}}))
;; # DB LIFECYCLE ENDPOINTS
;; # DB LIFECYCLE ENDPOINTS
...
@@ -59,7 +60,7 @@
...
@@ -59,7 +60,7 @@
{
:created_at
$
{
:created_at
$
:engine
"postgres"
; string because it's coming back from API instead of DB
:engine
"postgres"
; string because it's coming back from API instead of DB
:id
$
:id
$
:details
{
:host
"localhost"
,
:port
5432
,
:dbname
"fakedb"
,
:user
"cam"
}
:details
{
:host
"localhost"
,
:port
5432
,
:dbname
"fakedb"
,
:user
"cam"
,
:ssl
true
}
:updated_at
$
:updated_at
$
:name
db-name
:name
db-name
:is_sample
false
:is_sample
false
...
@@ -83,23 +84,17 @@
...
@@ -83,23 +84,17 @@
(
expect-let
[[
old-name
new-name
]
(
repeatedly
2
random-name
)
(
expect-let
[[
old-name
new-name
]
(
repeatedly
2
random-name
)
{
db-id
:id
}
(
create-db
old-name
)
{
db-id
:id
}
(
create-db
old-name
)
sel-db
(
fn
[]
(
sel
:one
:fields
[
Database
:name
:engine
:details
]
:id
db-id
))]
sel-db
(
fn
[]
(
sel
:one
:fields
[
Database
:name
:engine
:details
]
:id
db-id
))]
[{
:details
{
:host
"localhost"
,
:port
5432
,
:dbname
"fakedb"
,
:user
"cam"
}
[{
:details
{
:host
"localhost"
,
:port
5432
,
:dbname
"fakedb"
,
:user
"cam"
,
:ssl
true
}
:engine
:postgres
:engine
:postgres
:name
old-name
}
:name
old-name
}
{
:details
{
:host
"localhost"
,
:port
5432
,
:dbname
"fakedb"
,
:user
"rastacan"
}
{
:details
{
:host
"localhost"
,
:port
5432
,
:dbname
"fakedb"
,
:user
"rastacan"
}
:engine
:h2
:engine
:h2
:name
new-name
}
:name
new-name
}]
{
:details
{
:host
"localhost"
,
:port
5432
,
:dbname
"fakedb"
,
:user
"rastacan"
}
:engine
:h2
:name
old-name
}]
[(
sel-db
)
[(
sel-db
)
;; Check that we can update all the fields
;; Check that we can update all the fields
(
do
((
user->client
:crowberto
)
:put
200
(
format
"database/%d"
db-id
)
{
:name
new-name
(
do
((
user->client
:crowberto
)
:put
200
(
format
"database/%d"
db-id
)
{
:name
new-name
:engine
"h2"
:engine
"h2"
:details
{
:host
"localhost"
,
:port
5432
,
:dbname
"fakedb"
,
:user
"rastacan"
}})
:details
{
:host
"localhost"
,
:port
5432
,
:dbname
"fakedb"
,
:user
"rastacan"
}})
(
sel-db
))
;; Check that we can update just a single field
(
do
((
user->client
:crowberto
)
:put
200
(
format
"database/%d"
db-id
)
{
:name
old-name
})
(
sel-db
))])
(
sel-db
))])
;; # DATABASES FOR ORG
;; # DATABASES FOR ORG
...
...
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