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
89745fa0
Commit
89745fa0
authored
7 years ago
by
Arthur Ulfeldt
Browse files
Options
Downloads
Patches
Plain Diff
add tests to make sure we don't sync hidden tables
parent
0c927aaf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/metabase/sync_database/analyze_test.clj
+85
-2
85 additions, 2 deletions
test/metabase/sync_database/analyze_test.clj
with
85 additions
and
2 deletions
test/metabase/sync_database/analyze_test.clj
+
85
−
2
View file @
89745fa0
...
...
@@ -2,9 +2,15 @@
(
:require
[
clojure.string
:as
str
]
[
expectations
:refer
:all
]
[
metabase.db.metadata-queries
:as
metadata-queries
]
[
metabase.models
[
field
:refer
[
Field
]]
[
table
:as
table
:refer
[
Table
]]]
[
metabase.sync-database.analyze
:refer
:all
]
[
metabase.test.util
:as
tu
]))
[
metabase.test.data.users
:refer
:all
]
[
metabase.test.util
:as
tu
]
[
toucan.db
:as
db
]
[
toucan.util.test
:as
tt
]
[
metabase.driver
:as
driver
]))
;; test:cardinality-and-extract-field-values
;; (#2332) check that if field values are long we skip over them
...
...
@@ -72,3 +78,80 @@
(
expect
false
(
values-are-valid-emails?
[
100
]))
(
expect
false
(
values-are-valid-emails?
[
"true"
]))
(
expect
false
(
values-are-valid-emails?
[
"false"
]))
;; Tests to avoid analyzing hidden tables
(
defn
count-un-analyzed-fields
[
db_id
table-name
]
(
let
[
table-id
(
db/select-one-id
table/Table,
:db_id
db_id,
:active
true
:name
table-name
)]
(
assert
(
pos?
;; don't let ourselves be fooled if the test passes because the table is
;; totally broken or has no fields. Make sure we actually test something
(
db/count
metabase.models.field/Field
:table_id
table-id
)))
(
db/count
metabase.models.field/Field
:last_analyzed
nil
:table_id
table-id
)))
(
defn
get-latest-sync-time
[
db_id
table-name
]
(
let
[
table-id
(
db/select-one-id
table/Table,
:db_id
db_id,
:active
true
:name
table-name
)]
(
db/select-field
:last_analyzed
metabase.models.field/Field
:table_id
table-id
)))
(
defn
api-table-call
[
state
table
]
((
user->client
:crowberto
)
:put
200
(
format
"table/%d"
(
:id
table
))
{
:display_name
"hiddentable"
:entity_type
"person"
:visibility_type
state
:description
"What a nice table!"
}))
(
defn
api-sync-call
[
table
]
((
user->client
:crowberto
)
:post
200
(
format
"database/%d/sync"
(
:db_id
table
))
{}))
(
defn
sync-call
[
table
]
(
let
[
db-id
(
:db_id
table
)]
(
analyze-data-shape-for-tables!
(
driver/database-id->driver
db-id
)
{
:id
db-id
})))
;; expect all the kinds of hidden tables to stay un-analyzed through transitions and repeated syncing
(
tt/expect-with-temp
[
Table
[
table
{
:rows
15
}]
Field
[
field
{
:table_id
(
:id
table
)}]]
1
(
do
(
api-table-call
"hidden"
table
)
(
api-sync-call
table
)
(
api-table-call
"cruft"
table
)
(
api-table-call
"cruft"
table
)
(
api-sync-call
table
)
(
api-table-call
"technical"
table
)
(
api-sync-call
table
)
(
api-table-call
"technical"
table
)
(
api-sync-call
table
)
(
api-sync-call
table
)
(
count-un-analyzed-fields
(
:db_id
table
)
(
:name
table
))))
;; same test not coming through the api
(
tt/expect-with-temp
[
Table
[
table
{
:rows
15
}]
Field
[
field
{
:table_id
(
:id
table
)}]]
1
(
do
(
api-table-call
"hidden"
table
)
(
sync-call
table
)
(
api-table-call
"cruft"
table
)
(
api-table-call
"cruft"
table
)
(
sync-call
table
)
(
api-table-call
"technical"
table
)
(
sync-call
table
)
(
api-table-call
"technical"
table
)
(
sync-call
table
)
(
sync-call
table
)
(
count-un-analyzed-fields
(
:db_id
table
)
(
:name
table
))))
;; un-hiding a table should cause it to be analyzed
(
tt/expect-with-temp
[
Table
[
table
{
:rows
15
}]
Field
[
field
{
:table_id
(
:id
table
)}]]
0
(
do
(
api-table-call
"hidden"
table
)
(
api-table-call
nil
table
)
(
count-un-analyzed-fields
(
:db_id
table
)
(
:name
table
))))
;; re-hiding a table should not cause it to be analyzed
(
tt/expect-with-temp
[
Table
[
table
{
:rows
15
}]
Field
[
field
{
:table_id
(
:id
table
)}]]
(
do
(
api-table-call
"hidden"
table
)
(
api-table-call
nil
table
)
(
println
(
get-latest-sync-time
(
:db_id
table
)
(
:name
table
)))
(
get-latest-sync-time
(
:db_id
table
)
(
:name
table
)))
(
do
(
api-table-call
"hidden"
table
)
(
println
(
get-latest-sync-time
(
:db_id
table
)
(
:name
table
)))
(
get-latest-sync-time
(
:db_id
table
)
(
:name
table
))))
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