Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update acceptance tests #77

Merged
merged 3 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions test/macaw/acceptance_tests.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
(def broken-queries
"The DANGER ZONE
This map gives a pattern in the exception message we expect to receive when trying to analyze the given fixture."
{:broken/between #"Encountered unexpected token: \"BETWEEN\""
:broken/reserved #"Encountered unexpected token: \"final\" \"FINAL\""})
{:broken/between #"Encountered unexpected token: \"BETWEEN\""
:broken/filter-where #"Encountered unexpected token: \"\(\""})

(defn- fixture-analysis [fixture]
(some-> fixture (ct/fixture->filename "acceptance" ".analysis.edn") io/resource slurp read-string))
Expand All @@ -39,14 +39,15 @@
sql (ct/query-fixture fixture)
expected-cs (fixture-analysis fixture)
renames (fixture-renames fixture)
expected-rw (fixture-rewritten fixture)]
expected-rw (fixture-rewritten fixture)
opts {:non-reserved-words [:final]}]
(if-let [expected-msg (broken-queries fixture)]
(testing (str prefix " analysis cannot be parsed")
(is (thrown-with-msg? Exception
expected-msg
(ct/components sql))))
(ct/components sql opts))))
(when-let [cs (testing (str prefix " analysis does not throw")
(is (ct/components sql)))]
(is (ct/components sql opts)))]
(doseq [[ck cv] (dissoc expected-cs :overrides)]
(testing (str prefix " analysis is correct: " (name ck))
(let [actual-cv (get-component cs ck)
Expand All @@ -57,7 +58,7 @@
(when renames
(let [broken? (:broken? renames)
rewritten (testing (str prefix " rewriting does not throw")
(is (m/replace-names sql (dissoc renames :broken?))))]
(is (m/replace-names sql (dissoc renames :broken?) opts)))]
(when expected-rw
(testing (str prefix " rewritten SQL is correct")
(if broken?
Expand Down Expand Up @@ -97,4 +98,5 @@
(ns-unmap *ns* sym)))

(test-fixture :compound/cte)
)

(test-fixture :broken/filter-where))
7 changes: 7 additions & 0 deletions test/resources/acceptance/broken__filter_where.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select
e.instance_id
, percentile_cont(0.75) within group (order by e.running_time) as p75_time
-- the parser trips up on the opening bracket in the `filter (where ...)` clause
, percentile_cont(0.75) within group (order by e.running_time) filter (where e.error = '') as p75_success_time
from execution e
group by 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{:tables [{:table "employees"}]
:source-columns [{:table "employees", :column "id"}
{:table "employees", :column "manager_id"}
{:table "employees", :column "name"}]}
10 changes: 10 additions & 0 deletions test/resources/acceptance/compound__cte_recursive.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
WITH RECURSIVE hierarchy AS (
SELECT id, manager_id, name
FROM employees
WHERE manager_id IS NULL
UNION ALL
SELECT e.id, e.manager_id, e.name
FROM employees e
JOIN hierarchy eh ON e.manager_id = eh.id
)
SELECT * FROM hierarchy;
Loading