History

Merge remote-tracking branch 'origin/codex/effect-lint-storage-postgres-tests' into codex/effect-lint-integration

Rhys Sullivan committed 6 months ago

Commit d56487f2 parents 282e7c6 987638b1 file · +24 −12Browse files

Unified · Split

packages/core/storage-postgres/src/index.test.ts+24−12
@@ -7,7 +7,7 @@ · 6 unmodified lines
7// cloud test DB on 5434.7// cloud test DB on 5434.
8 8
9import { describe, expect, it } from "@effect/vitest";9import { describe, expect, it } from "@effect/vitest";
10import { Effect } from "effect";10import { Data, Effect } from "effect";
11import postgres from "postgres";11import postgres from "postgres";
12import { drizzle } from "drizzle-orm/postgres-js";12import { drizzle } from "drizzle-orm/postgres-js";
13import { relations } from "drizzle-orm";13import { relations } from "drizzle-orm";
@@ -21,7 +21,7 @@ import { · 7 unmodified lines
21 jsonb,21 jsonb,
22} from "drizzle-orm/pg-core";22} from "drizzle-orm/pg-core";
23 23
24import type { DBAdapter } from "@executor-js/storage-core";24import type { DBAdapter, StorageFailure } from "@executor-js/storage-core";
25import {25import {
26 conformanceSchema,26 conformanceSchema,
27 runAdapterConformance,27 runAdapterConformance,
@@ -31,6 +31,13 @@ import { makePostgresAdapter } from "./index"; · 3 unmodified lines
31 31
32const url = "postgresql://postgres:postgres@127.0.0.1:5435/postgres";32const url = "postgresql://postgres:postgres@127.0.0.1:5435/postgres";
33 33
34class PostgresTestDatabaseError extends Data.TaggedError(
35 "PostgresTestDatabaseError",
36)<{
37 readonly message: string;
38 readonly cause: unknown;
39}> {}
40
34// max=1 so BEGIN/COMMIT sent via `db.execute(sql.raw(...))` always hit41// max=1 so BEGIN/COMMIT sent via `db.execute(sql.raw(...))` always hit
35// the same connection — postgres.js with a larger pool rejects unsafe42// the same connection — postgres.js with a larger pool rejects unsafe
36// transaction control that isn't bound to a single reserved client.43// transaction control that isn't bound to a single reserved client.
@@ -135,9 +142,10 @@ const createConformanceTables = Effect.tryPromise({ · 98 unmodified lines
135 );142 );
136 },143 },
137 catch: (cause) =>144 catch: (cause) =>
138 new Error(145 new PostgresTestDatabaseError({
139 `failed to create postgres conformance tables: ${String(cause)}`,146 message: "failed to create postgres conformance tables",
140 ),147 cause,
148 }),
141});149});
142 150
143const resetTables = Effect.gen(function* () {151const resetTables = Effect.gen(function* () {
@@ -145,18 +153,19 @@ const resetTables = Effect.gen(function* () { · 1 unmodified line
145 try: () =>153 try: () =>
146 sql`DROP TABLE IF EXISTS "source", "tag", "source_tag", "with_defaults", "blob" CASCADE`.then(154 sql`DROP TABLE IF EXISTS "source", "tag", "source_tag", "with_defaults", "blob" CASCADE`.then(
147 () => undefined,155 () => undefined,
148 ),156 ),
149 catch: (cause) =>157 catch: (cause) =>
150 new Error(158 new PostgresTestDatabaseError({
151 `failed to reset postgres conformance tables: ${String(cause)}`,159 message: "failed to reset postgres conformance tables",
152 ),160 cause,
161 }),
153 });162 });
154 yield* createConformanceTables;163 yield* createConformanceTables;
155});164});
156 165
157const withAdapter = <A, E>(166const withAdapter = <A, E>(
158 fn: (adapter: DBAdapter) => Effect.Effect<A, E>,167 fn: (adapter: DBAdapter) => Effect.Effect<A, E>,
159): Effect.Effect<A, E | Error> =>168): Effect.Effect<A, E | StorageFailure | PostgresTestDatabaseError> =>
160 Effect.gen(function* () {169 Effect.gen(function* () {
161 yield* resetTables;170 yield* resetTables;
162 const db = drizzle(sql, { schema: conformanceTables });171 const db = drizzle(sql, { schema: conformanceTables });
@@ -165,7 +174,7 @@ const withAdapter = <A, E>( · 2 unmodified lines
165 schema: conformanceSchema,174 schema: conformanceSchema,
166 });175 });
167 return yield* fn(adapter);176 return yield* fn(adapter);
168 }) as Effect.Effect<A, E | Error>;177 });
169 178
170runAdapterConformance("postgres", withAdapter);179runAdapterConformance("postgres", withAdapter);
171 180
@@ -191,7 +200,10 @@ const resetScopedTable = Effect.tryPromise({ · 19 unmodified lines
191 );200 );
192 },201 },
193 catch: (cause) =>202 catch: (cause) =>
194 new Error(`failed to reset scoped_item table: ${String(cause)}`),203 new PostgresTestDatabaseError({
204 message: "failed to reset scoped_item table",
205 cause,
206 }),
195});207});
196 208
197const makeScopedAdapter = () =>209const makeScopedAdapter = () =>