Skip to content

Commit

Permalink
Driver tests with both edgedb and gel env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
diksipav committed Jan 16, 2025
1 parent b4814a4 commit 26d93ce
Show file tree
Hide file tree
Showing 2 changed files with 179 additions and 1 deletion.
178 changes: 178 additions & 0 deletions packages/driver/test/connection-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,26 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: false,
fromEnv: false,
},
{
opts: { user: "user" },
env: {
EDGEDB_DATABASE: "testdb",
EDGEDB_PASSWORD: "passw",
EDGEDB_HOST: "host",
EDGEDB_PORT: "123",
},
result: {
...defaults,
address: ["host", 123],
user: "user",
database: "testdb",
password: "passw",
},
logging: true,
inProject: false,
fromProject: false,
fromEnv: true,
},
{
opts: { user: "user" },
env: {
Expand All @@ -492,6 +512,23 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: false,
fromEnv: true,
},
{
opts: { dsn: "edgedb://", user: "user" },
env: {
EDGEDB_DATABASE: "testdb",
EDGEDB_PASSWORD: "passw",
EDGEDB_HOST: "host",
EDGEDB_PORT: "123",
},
result: {
...defaults,
user: "user",
},
logging: true,
inProject: false,
fromProject: false,
fromEnv: false,
},
{
opts: { dsn: "edgedb://", user: "user" },
env: {
Expand All @@ -509,6 +546,23 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: false,
fromEnv: false,
},
{
opts: { dsn: "gel://", user: "user" },
env: {
EDGEDB_DATABASE: "testdb",
EDGEDB_PASSWORD: "passw",
EDGEDB_HOST: "host",
EDGEDB_PORT: "123",
},
result: {
...defaults,
user: "user",
},
logging: true,
inProject: false,
fromProject: false,
fromEnv: false,
},
{
opts: { dsn: "gel://", user: "user" },
env: {
Expand All @@ -526,6 +580,37 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: false,
fromEnv: false,
},
{
opts: { user: "user" },
env: {
EDGEDB_DATABASE: "testdb",
EDGEDB_PASSWORD: "passw",
},
fs: {
cwd: "/home/edgedb/test",
homedir: "/home/edgedb",
files: {
"/home/edgedb/test/gel.toml": "",
"/home/edgedb/.config/edgedb/projects/test-cf3c86df8fc33fbb73a47671ac5762eda8219158":
"",
"/home/edgedb/.config/edgedb/projects/test-cf3c86df8fc33fbb73a47671ac5762eda8219158/instance-name":
"test_project",
"/home/edgedb/.config/edgedb/credentials/test_project.json":
'{"port": 10702, "user": "test3n", "password": "lZTBy1RVCfOpBAOwSCwIyBIR", "database": "test3n"}',
},
},
result: {
...defaults,
address: ["localhost", 10702],
user: "user",
database: "testdb",
password: "passw",
},
logging: true,
inProject: true,
fromProject: true,
fromEnv: true,
},
{
opts: { user: "user" },
env: {
Expand Down Expand Up @@ -557,6 +642,37 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: true,
fromEnv: true,
},
{
opts: { user: "user", database: "db", password: "secret" },
env: {
EDGEDB_DATABASE: "testdb",
EDGEDB_PASSWORD: "passw",
},
fs: {
cwd: "/home/edgedb/test",
homedir: "/home/edgedb",
files: {
"/home/edgedb/test/gel.toml": "",
"/home/edgedb/.config/edgedb/projects/test-cf3c86df8fc33fbb73a47671ac5762eda8219158":
"",
"/home/edgedb/.config/edgedb/projects/test-cf3c86df8fc33fbb73a47671ac5762eda8219158/instance-name":
"test_project",
"/home/edgedb/.config/edgedb/credentials/test_project.json":
'{"port": 10702, "user": "test3n", "password": "lZTBy1RVCfOpBAOwSCwIyBIR", "database": "test3n"}',
},
},
result: {
...defaults,
address: ["localhost", 10702],
user: "user",
database: "db",
password: "secret",
},
logging: true,
inProject: true,
fromProject: true,
fromEnv: false,
},
{
opts: { user: "user", database: "db", password: "secret" },
env: {
Expand Down Expand Up @@ -588,6 +704,28 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: true,
fromEnv: false,
},
{
opts: { host: "test.local" },
env: {
EDGEDB_DATABASE: "testdb",
EDGEDB_PASSWORD: "passw",
},
fs: {
cwd: "/home/edgedb/test",
homedir: "/home/edgedb",
files: {
"/home/edgedb/test/gel.toml": "",
},
},
result: {
...defaults,
address: ["test.local", 5656],
},
logging: true,
inProject: true,
fromProject: false,
fromEnv: false,
},
{
opts: { host: "test.local" },
env: {
Expand Down Expand Up @@ -642,6 +780,46 @@ test("logging, inProject, fromProject, fromEnv", async () => {
}
});

test("EDGEDB_CLIENT_SECURITY env var", async () => {
const truthTable: [string, string, string | null][] = [
// CLIENT_SECURITY, CLIENT_TLS_SECURITY, result
["default", "default", "default"],
["default", "insecure", "insecure"],
["default", "no_host_verification", "no_host_verification"],
["default", "strict", "strict"],
["insecure_dev_mode", "default", "insecure"],
["insecure_dev_mode", "insecure", "insecure"],
["insecure_dev_mode", "no_host_verification", "no_host_verification"],
["insecure_dev_mode", "strict", "strict"],
["strict", "default", "strict"],
["strict", "insecure", null],
["strict", "no_host_verification", null],
["strict", "strict", "strict"],
];

for (const [clientSecurity, clientTlsSecurity, result] of truthTable) {
await envWrap(
{
env: {
EDGEDB_CLIENT_SECURITY: clientSecurity,
},
},
async () => {
const parseConnectArgs = parseConnectArguments({
host: "localhost",
tlsSecurity: clientTlsSecurity as any,
});
if (!result) {
await expect(parseConnectArgs).rejects.toThrow();
} else {
const { connectionParams } = await parseConnectArgs;
expect(connectionParams._tlsSecurity).toBe(result);
}
},
);
}
});

test("GEL_CLIENT_SECURITY env var", async () => {
const truthTable: [string, string, string | null][] = [
// CLIENT_SECURITY, CLIENT_TLS_SECURITY, result
Expand Down
2 changes: 1 addition & 1 deletion packages/driver/test/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const startServer = async (
statusFile: string,
env: { [key: string]: string } = {},
): Promise<ServerInst> => {
if (process.env.GEL_DEBUG_SERVER) {
if (process.env.GEL_DEBUG_SERVER || process.env.EDGEDB_DEBUG_SERVER) {
console.log(`running command: ${cmd.join(" ")}`);
}

Expand Down

0 comments on commit 26d93ce

Please sign in to comment.