Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
82 additions
and
65 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#! /usr/bin/env deno run --allow-net --allow-env test.ts | ||
import { runTests } from "./deps.ts"; | ||
|
||
import "./tests/data_types.ts"; | ||
import "./tests/queries.ts"; | ||
import "./tests/connection_params.ts"; | ||
import "./tests/client.ts"; | ||
import "./tests/pool.ts"; | ||
import "./tests/utils.ts"; | ||
import "./tests/decode.ts"; | ||
|
||
runTests(); |
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,56 @@ | ||
import { assertEquals } from "../deps.ts"; | ||
import { Client } from "../mod.ts"; | ||
import { TEST_CONNECTION_PARAMS } from "./constants.ts"; | ||
import { getTestClient } from "./helpers.ts"; | ||
|
||
const SETUP = [ | ||
"DROP TABLE IF EXISTS data_types;", | ||
`CREATE TABLE data_types( | ||
inet_t inet, | ||
macaddr_t macaddr, | ||
cidr_t cidr | ||
);` | ||
]; | ||
|
||
const CLIENT = new Client(TEST_CONNECTION_PARAMS); | ||
|
||
const testClient = getTestClient(CLIENT, SETUP); | ||
|
||
testClient(async function inet() { | ||
const inet = "127.0.0.1"; | ||
const insertRes = await CLIENT.query( | ||
"INSERT INTO data_types (inet_t) VALUES($1)", | ||
inet | ||
); | ||
const selectRes = await CLIENT.query( | ||
"SELECT inet_t FROM data_types WHERE inet_t=$1", | ||
inet | ||
); | ||
assertEquals(selectRes.rows, [[inet]]); | ||
}); | ||
|
||
testClient(async function macaddr() { | ||
const macaddr = "08:00:2b:01:02:03"; | ||
const insertRes = await CLIENT.query( | ||
"INSERT INTO data_types (macaddr_t) VALUES($1)", | ||
macaddr | ||
); | ||
const selectRes = await CLIENT.query( | ||
"SELECT macaddr_t FROM data_types WHERE macaddr_t=$1", | ||
macaddr | ||
); | ||
assertEquals(selectRes.rows, [[macaddr]]); | ||
}); | ||
|
||
testClient(async function cidr() { | ||
const cidr = "192.168.100.128/25"; | ||
const insertRes = await CLIENT.query( | ||
"INSERT INTO data_types (cidr_t) VALUES($1)", | ||
cidr | ||
); | ||
const selectRes = await CLIENT.query( | ||
"SELECT cidr_t FROM data_types WHERE cidr_t=$1", | ||
cidr | ||
); | ||
assertEquals(selectRes.rows, [[cidr]]); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,22 @@ | ||
import { test, TestFunction } from "../deps.ts"; | ||
|
||
export function getTestClient(client, defSetupQueries) { | ||
return async function testClient( | ||
t: TestFunction, | ||
setupQueries?: Array<string> | ||
) { | ||
const fn = async () => { | ||
try { | ||
await client.connect(); | ||
for (const q of setupQueries || defSetupQueries) { | ||
await client.query(q); | ||
} | ||
await t(); | ||
} finally { | ||
await client.end(); | ||
} | ||
}; | ||
const name = t.name; | ||
test({ fn, name }); | ||
}; | ||
} |
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