-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tap test in infra and info assurance patterns #44
- Loading branch information
1 parent
b473db1
commit 61d692d
Showing
16 changed files
with
1,815 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
DROP VIEW IF EXISTS "synthetic_test_suite"; | ||
CREATE VIEW "synthetic_test_suite" AS | ||
WITH | ||
tap_version AS (SELECT 'TAP version 14' AS tap_result), | ||
tap_plan AS (SELECT '1..6' AS tap_result), | ||
-- 0: Check if a view 'control_regimes' exists | ||
"Check if a view 'control_regimes' exists" AS ( | ||
WITH test_case AS ( | ||
SELECT count(name) as exist FROM sqlite_master WHERE type = 'view' AND name = 'control_regimes' | ||
) | ||
SELECT CASE WHEN exist = 1 THEN 'ok 0 ' || ('View "control_regimes" exists in the DB') ELSE 'not ok 0 ' || ('View "control_regimes" not exists in the DB') END AS tap_result FROM test_case | ||
), | ||
-- 1: Ensure 'control_regimes' view has values | ||
"Ensure 'control_regimes' view has values " AS ( | ||
WITH test_case AS ( | ||
SELECT COUNT(*) AS control_regimes_count FROM control_regimes | ||
) | ||
SELECT CASE WHEN control_regimes_count > 0 THEN 'ok 1 ' || ('control_regimes_count is greater than 0') ELSE 'not ok 1 ' || ('control_regimes_count should be greater than 0, is ' || control_regimes_count || ' instead') END AS tap_result FROM test_case | ||
), | ||
-- 2: Check if a view 'control_group' exists | ||
"Check if a view 'control_group' exists" AS ( | ||
WITH test_case AS ( | ||
SELECT count(name) as exist FROM sqlite_master WHERE type = 'view' AND name = 'control_group' | ||
) | ||
SELECT CASE WHEN exist = 1 THEN 'ok 2 ' || ('View "control_group" exists in the DB') ELSE 'not ok 2 ' || ('View "control_group" not exists in the DB') END AS tap_result FROM test_case | ||
), | ||
-- 3: Ensure 'control_group' view has values | ||
"Ensure 'control_group' view has values " AS ( | ||
WITH test_case AS ( | ||
SELECT COUNT(*) AS control_group_count FROM control_group | ||
) | ||
SELECT CASE WHEN control_group_count > 0 THEN 'ok 3 ' || ('control_group_count is greater than 0') ELSE 'not ok 3 ' || ('control_group_count should be greater than 0, is ' || control_group_count || ' instead') END AS tap_result FROM test_case | ||
), | ||
-- 4: Check if a view 'control' exists | ||
"Check if a view 'control' exists" AS ( | ||
WITH test_case AS ( | ||
SELECT count(name) as exist FROM sqlite_master WHERE type = 'view' AND name = 'control' | ||
) | ||
SELECT CASE WHEN exist = 1 THEN 'ok 4 ' || ('View "control" exists in the DB') ELSE 'not ok 4 ' || ('View "control" not exists in the DB') END AS tap_result FROM test_case | ||
), | ||
-- 5: Ensure 'control' view has values | ||
"Ensure 'control' view has values " AS ( | ||
WITH test_case AS ( | ||
SELECT COUNT(*) AS control_count FROM control | ||
) | ||
SELECT CASE WHEN control_count > 0 THEN 'ok 5 ' || ('control_count is greater than 0') ELSE 'not ok 5 ' || ('control_count should be greater than 0, is ' || control_count || ' instead') END AS tap_result FROM test_case | ||
) | ||
SELECT tap_result FROM tap_version | ||
UNION ALL | ||
SELECT tap_result FROM tap_plan | ||
UNION ALL | ||
SELECT tap_result FROM "Check if a view 'control_regimes' exists" | ||
UNION ALL | ||
SELECT tap_result FROM "Ensure 'control_regimes' view has values " | ||
UNION ALL | ||
SELECT tap_result FROM "Check if a view 'control_group' exists" | ||
UNION ALL | ||
SELECT tap_result FROM "Ensure 'control_group' view has values " | ||
UNION ALL | ||
SELECT tap_result FROM "Check if a view 'control' exists" | ||
UNION ALL | ||
SELECT tap_result FROM "Ensure 'control' view has values "; | ||
SELECT * FROM synthetic_test_suite; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { tapNB } from "../../std/notebook/mod.ts"; | ||
type TestCaseContext = tapNB.TestCaseContext; | ||
export class SyntheticTestSuite extends tapNB.TestSuiteNotebook { | ||
// any method that ends in DDL, SQL, DML, or DQL will be "arbitrary SQL" | ||
// and included in the SQL stream before all the test cases | ||
|
||
"Check if a view 'control_regimes' exists"(ctx: TestCaseContext) { | ||
const viewName = "control_regimes"; | ||
return this.assertThat(ctx)` | ||
SELECT count(name) as exist FROM sqlite_master WHERE type = 'view' AND name = '${viewName}'` | ||
.case( | ||
`exist = 1`, | ||
`View "${viewName}" exists in the DB`, | ||
`View "${viewName}" not exists in the DB`, | ||
); | ||
} | ||
|
||
"Ensure 'control_regimes' view has values "(ctx: TestCaseContext) { | ||
return this.assertThat<"control_regimes_count">(ctx)` | ||
SELECT COUNT(*) AS control_regimes_count FROM control_regimes` | ||
.greaterThan("control_regimes_count", 0); | ||
} | ||
|
||
"Check if a view 'control_group' exists"(ctx: TestCaseContext) { | ||
const viewName = "control_group"; | ||
return this.assertThat(ctx)` | ||
SELECT count(name) as exist FROM sqlite_master WHERE type = 'view' AND name = '${viewName}'` | ||
.case( | ||
`exist = 1`, | ||
`View "${viewName}" exists in the DB`, | ||
`View "${viewName}" not exists in the DB`, | ||
); | ||
} | ||
|
||
"Ensure 'control_group' view has values "(ctx: TestCaseContext) { | ||
return this.assertThat<"control_group_count">(ctx)` | ||
SELECT COUNT(*) AS control_group_count FROM control_group` | ||
.greaterThan("control_group_count", 0); | ||
} | ||
|
||
"Check if a view 'control' exists"(ctx: TestCaseContext) { | ||
const viewName = "control"; | ||
return this.assertThat(ctx)` | ||
SELECT count(name) as exist FROM sqlite_master WHERE type = 'view' AND name = '${viewName}'` | ||
.case( | ||
`exist = 1`, | ||
`View "${viewName}" exists in the DB`, | ||
`View "${viewName}" not exists in the DB`, | ||
); | ||
} | ||
|
||
"Ensure 'control' view has values "(ctx: TestCaseContext) { | ||
return this.assertThat<"control_count">(ctx)` | ||
SELECT COUNT(*) AS control_count FROM control` | ||
.greaterThan("control_count", 0); | ||
} | ||
} | ||
|
||
// this will be used by any callers who want to serve it as a CLI with SDTOUT | ||
if (import.meta.main) { | ||
const SQL = await tapNB.TestSuiteNotebook.SQL( | ||
new SyntheticTestSuite("synthetic_test_suite"), | ||
); | ||
|
||
console.log(SQL.join("\n")); | ||
console.log(`SELECT * FROM synthetic_test_suite;`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.