-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for the hyperdrive binding
- Loading branch information
1 parent
476b3fa
commit 0b19306
Showing
1 changed file
with
64 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
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; | ||
} | ||
|
||
const TEST_CONN_STRING = `postgresql://user:password@localhost:5432/database`; | ||
|
||
const opts: Partial<MiniflareOptions> = { | ||
hyperdrives: { | ||
hyperdrive: TEST_CONN_STRING, | ||
}, | ||
}; | ||
|
||
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") | ||
); | ||
}); | ||
|
||
test("connectionString: different from configuration", async (t) => { | ||
const hyperdrive = t.context.hyperdrive; | ||
t.not(hyperdrive.connectionString, TEST_CONN_STRING); | ||
}); | ||
|
||
test("user: matches configuration", async (t) => { | ||
const hyperdrive = t.context.hyperdrive; | ||
t.is(hyperdrive.user, "user"); | ||
}); | ||
|
||
test("password: matches configuration", async (t) => { | ||
const hyperdrive = t.context.hyperdrive; | ||
t.is(hyperdrive.password, "password"); | ||
}); | ||
|
||
test("database: matches configuration", async (t) => { | ||
const hyperdrive = t.context.hyperdrive; | ||
t.is(hyperdrive.database, "database"); | ||
}); | ||
|
||
test("host: randomized", async (t) => { | ||
const hyperdrive = t.context.hyperdrive; | ||
t.not(hyperdrive.host, "localhost"); | ||
}); |