48 lines
1.7 KiB
TypeScript
48 lines
1.7 KiB
TypeScript
import { PgConnection } from "@effect/sql-pg"
|
|
import { assert, describe, it } from "@effect/vitest"
|
|
import { Effect, Redacted } from "effect"
|
|
|
|
describe("PgConnection config", () => {
|
|
it.effect("rejects sslmode=prefer in a URL", () =>
|
|
Effect.gen(function*() {
|
|
const error = yield* Effect.flip(PgConnection.make({
|
|
url: Redacted.make("postgres://user@localhost/db?sslmode=prefer")
|
|
}))
|
|
assert.strictEqual(error.reason._tag, "ConnectionError")
|
|
assert.include(error.reason.message, "sslmode")
|
|
}))
|
|
|
|
it.effect("rejects sslmode=allow in a URL", () =>
|
|
Effect.gen(function*() {
|
|
const error = yield* Effect.flip(PgConnection.make({
|
|
url: Redacted.make("postgresql://user@localhost/db?sslmode=allow")
|
|
}))
|
|
assert.strictEqual(error.reason._tag, "ConnectionError")
|
|
assert.include(error.reason.message, "sslmode")
|
|
}))
|
|
|
|
it.effect("lets explicit ssl override sslmode=prefer in a URL", () =>
|
|
Effect.gen(function*() {
|
|
let connected = false
|
|
const error = yield* Effect.flip(PgConnection.make({
|
|
url: Redacted.make("postgres://user@localhost/db?sslmode=prefer"),
|
|
ssl: false,
|
|
stream: () => {
|
|
connected = true
|
|
throw new Error("test connection")
|
|
}
|
|
}))
|
|
assert.isTrue(connected)
|
|
assert.strictEqual(error.reason._tag, "ConnectionError")
|
|
assert.strictEqual(error.reason.message, "PgConnection: Failed to connect")
|
|
}))
|
|
|
|
it.effect("rejects a non-postgres URL protocol", () =>
|
|
Effect.gen(function*() {
|
|
const error = yield* Effect.flip(PgConnection.make({
|
|
url: Redacted.make("mysql://user@localhost/db")
|
|
}))
|
|
assert.strictEqual(error.reason._tag, "ConnectionError")
|
|
}))
|
|
})
|