Skip to content

Commit

Permalink
fixup! Add Hyperdrive Binding support
Browse files Browse the repository at this point in the history
  • Loading branch information
tmthecoder committed Oct 18, 2023
1 parent fb7eeb1 commit 6938edd
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions packages/miniflare/test/plugins/hyperdrive/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
import { Server, createServer } from "net";
import { Hyperdrive } from "@cloudflare/workers-types/experimental";
import { MiniflareOptions, ReplaceWorkersTypes } from "miniflare";
import {
MiniflareDurableObjectControlStub,
MiniflareTestContext,
Namespaced,
miniflareTest,
namespace,
} from "../../test-shared";

interface Context extends MiniflareTestContext {
ns: string;
hyperdrive: Namespaced<ReplaceWorkersTypes<Hyperdrive>>;
object: MiniflareDurableObjectControlStub;
}
import { MiniflareOptions } from "miniflare";
import { MiniflareTestContext, miniflareTest } from "../../test-shared";

const TEST_CONN_STRING = `postgresql://user:password@localhost:5432/database`;

Expand All @@ -23,42 +10,45 @@ const opts: Partial<MiniflareOptions> = {
},
};

const test = miniflareTest<unknown, Context>(opts, async (global) => {
return new global.Response(null, { status: 404 });
});

test.beforeEach(async (t) => {
const ns = `${Date.now()}_${Math.floor(
Math.random() * Number.MAX_SAFE_INTEGER
)}`;
t.context.ns = ns;
t.context.hyperdrive = namespace(
ns,
await t.context.mf.getHyperdrive("hyperdrive")
);
});
const test = miniflareTest<{ hyperdrive: Hyperdrive }, MiniflareTestContext>(
opts,
async (global, _, env) => {
return global.Response.json({
connectionString: env.hyperdrive.connectionString,
user: env.hyperdrive.user,
password: env.hyperdrive.password,
database: env.hyperdrive.database,
host: env.hyperdrive.host,
});
}
);

test("connectionString: different from configuration", async (t) => {
const hyperdrive = t.context.hyperdrive;
const hyperdriveResp = await t.context.mf.dispatchFetch("http://localhost/");
const hyperdrive = await hyperdriveResp.json();
t.not(hyperdrive.connectionString, TEST_CONN_STRING);

Check failure on line 29 in packages/miniflare/test/plugins/hyperdrive/index.spec.ts

View workflow job for this annotation

GitHub Actions / Lint & Type Check

'hyperdrive' is of type 'unknown'.
});

test("user: matches configuration", async (t) => {
const hyperdrive = t.context.hyperdrive;
const hyperdriveResp = await t.context.mf.dispatchFetch("http://localhost/");
const hyperdrive = await hyperdriveResp.json();
t.is(hyperdrive.user, "user");

Check failure on line 35 in packages/miniflare/test/plugins/hyperdrive/index.spec.ts

View workflow job for this annotation

GitHub Actions / Lint & Type Check

'hyperdrive' is of type 'unknown'.
});

test("password: matches configuration", async (t) => {
const hyperdrive = t.context.hyperdrive;
const hyperdriveResp = await t.context.mf.dispatchFetch("http://localhost/");
const hyperdrive = await hyperdriveResp.json();
t.is(hyperdrive.password, "password");

Check failure on line 41 in packages/miniflare/test/plugins/hyperdrive/index.spec.ts

View workflow job for this annotation

GitHub Actions / Lint & Type Check

'hyperdrive' is of type 'unknown'.
});

test("database: matches configuration", async (t) => {
const hyperdrive = t.context.hyperdrive;
const hyperdriveResp = await t.context.mf.dispatchFetch("http://localhost/");
const hyperdrive = await hyperdriveResp.json();
t.is(hyperdrive.database, "database");

Check failure on line 47 in packages/miniflare/test/plugins/hyperdrive/index.spec.ts

View workflow job for this annotation

GitHub Actions / Lint & Type Check

'hyperdrive' is of type 'unknown'.
});

test("host: randomized", async (t) => {
const hyperdrive = t.context.hyperdrive;
const hyperdriveResp = await t.context.mf.dispatchFetch("http://localhost/");
const hyperdrive = await hyperdriveResp.json();
t.not(hyperdrive.host, "localhost");

Check failure on line 53 in packages/miniflare/test/plugins/hyperdrive/index.spec.ts

View workflow job for this annotation

GitHub Actions / Lint & Type Check

'hyperdrive' is of type 'unknown'.
});

0 comments on commit 6938edd

Please sign in to comment.