|
| 1 | +import { testingAsserts as ta } from "../../deps-test.ts"; |
| 2 | +import * as mod from "./atc.ts"; |
| 3 | + |
| 4 | +Deno.test("osQueryATCConfigSupplier with auto-generated queries", () => { |
| 5 | + function* tables() { |
| 6 | + yield { |
| 7 | + tableName: "test_table", |
| 8 | + columns: [{ columnName: "column1" }, { columnName: "column2" }], |
| 9 | + }; |
| 10 | + yield { |
| 11 | + tableName: "test_table2", |
| 12 | + columns: [{ columnName: "column2_1" }, { columnName: "column2_2" }], |
| 13 | + }; |
| 14 | + } |
| 15 | + const configSupplier = mod.osQueryATCConfigSupplier(tables()); |
| 16 | + |
| 17 | + ta.assertEquals( |
| 18 | + configSupplier(( |
| 19 | + suggested: string, |
| 20 | + atcPartial: Omit<mod.OsQueryAutoTableConstrRecord, "path">, |
| 21 | + ) => ({ |
| 22 | + osQueryTableName: suggested, |
| 23 | + atcRec: { ...atcPartial, path: "./sqlite-src.db" }, |
| 24 | + })), |
| 25 | + { |
| 26 | + auto_table_construction: { |
| 27 | + test_table: { |
| 28 | + query: "select column1, column2 from test_table", |
| 29 | + columns: ["column1", "column2"], |
| 30 | + path: "./sqlite-src.db", |
| 31 | + }, |
| 32 | + test_table2: { |
| 33 | + query: "select column2_1, column2_2 from test_table2", |
| 34 | + columns: ["column2_1", "column2_2"], |
| 35 | + path: "./sqlite-src.db", |
| 36 | + }, |
| 37 | + }, |
| 38 | + }, |
| 39 | + ); |
| 40 | +}); |
| 41 | + |
| 42 | +Deno.test("osQueryATCConfigSupplier with custom query", () => { |
| 43 | + function* tables() { |
| 44 | + yield { |
| 45 | + tableName: "test_table", |
| 46 | + columns: [{ columnName: "column1" }, { columnName: "column2" }], |
| 47 | + query: |
| 48 | + "select column1 as 'special1', column2 as 'special2' from test_table", |
| 49 | + }; |
| 50 | + } |
| 51 | + |
| 52 | + const atcRecConfig = ( |
| 53 | + suggested: string, |
| 54 | + atcPartial: Omit<mod.OsQueryAutoTableConstrRecord, "path">, |
| 55 | + ) => ({ |
| 56 | + osQueryTableName: suggested, |
| 57 | + atcRec: { ...atcPartial, path: "./sqlite-src.db" }, |
| 58 | + }); |
| 59 | + |
| 60 | + const configSupplier = mod.osQueryATCConfigSupplier(tables()); |
| 61 | + const config: mod.OsQueryAutoTableConstrConfig = configSupplier(atcRecConfig); |
| 62 | + |
| 63 | + const expected: mod.OsQueryAutoTableConstrConfig = { |
| 64 | + auto_table_construction: { |
| 65 | + test_table: { |
| 66 | + query: |
| 67 | + "select column1 as 'special1', column2 as 'special2' from test_table", |
| 68 | + columns: ["column1", "column2"], |
| 69 | + path: "./sqlite-src.db", |
| 70 | + }, |
| 71 | + }, |
| 72 | + }; |
| 73 | + |
| 74 | + ta.assertEquals(config, expected); |
| 75 | +}); |
0 commit comments