diff options
author | 2023-07-04 19:40:26 -0300 | |
---|---|---|
committer | 2023-07-04 15:40:26 -0700 | |
commit | 979e99940374289e21332a0a7214889648e7397b (patch) | |
tree | 5b17ef26b04df20c7a590a3f3cd28c8f52e622fd /test/js/third_party/postgres/postgres.test.ts | |
parent | c2755f770cb0d6296c82a6f6d633d62307449028 (diff) | |
download | bun-979e99940374289e21332a0a7214889648e7397b.tar.gz bun-979e99940374289e21332a0a7214889648e7397b.tar.zst bun-979e99940374289e21332a0a7214889648e7397b.zip |
[tls] fix servername (#3513)
* fix servername
* add postgres tls tests
* update test packages
* add basic CRUD test
Diffstat (limited to 'test/js/third_party/postgres/postgres.test.ts')
-rw-r--r-- | test/js/third_party/postgres/postgres.test.ts | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/js/third_party/postgres/postgres.test.ts b/test/js/third_party/postgres/postgres.test.ts new file mode 100644 index 000000000..490192ae7 --- /dev/null +++ b/test/js/third_party/postgres/postgres.test.ts @@ -0,0 +1,56 @@ +import { test, expect, describe } from "bun:test"; +import { Pool } from "pg"; +import { parse } from "pg-connection-string"; +import postgres from "postgres"; + +const CONNECTION_STRING = process.env.TLS_POSTGRES_DATABASE_URL; + +const it = CONNECTION_STRING ? test : test.skip; + +describe("pg", () => { + it("should connect using TLS", async () => { + const pool = new Pool(parse(CONNECTION_STRING as string)); + try { + const { rows } = await pool.query("SELECT version()", []); + const [{ version }] = rows; + + expect(version).toMatch(/PostgreSQL/); + } finally { + pool.end(); + } + }); +}); + +describe("postgres", () => { + it("should connect using TLS", async () => { + const sql = postgres(CONNECTION_STRING as string); + try { + const [{ version }] = await sql`SELECT version()`; + expect(version).toMatch(/PostgreSQL/); + } finally { + sql.end(); + } + }); + + it("should insert, select and delete", async () => { + const sql = postgres(CONNECTION_STRING as string); + try { + await sql`CREATE TABLE IF NOT EXISTS users ( + user_id serial PRIMARY KEY, + username VARCHAR ( 50 ) NOT NULL + );`; + + const [{ user_id, username }] = await sql`insert into users (username) values ('bun') returning *`; + expect(username).toBe("bun"); + + const [{ user_id: user_id2, username: username2 }] = await sql`select * from users where user_id = ${user_id}`; + expect(username2).toBe("bun"); + expect(user_id2).toBe(user_id); + + const [{ username: username3 }] = await sql`delete from users where user_id = ${user_id} returning *`; + expect(username3).toBe("bun"); + } finally { + sql.end(); + } + }); +}); |