Skip to content

Commit

Permalink
Driver tests with both edgedb and gel env vars (#1176)
Browse files Browse the repository at this point in the history
I'll add test explanations in the morning.
  • Loading branch information
diksipav committed Feb 14, 2025
1 parent 9e1c33b commit d6c17a7
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 6 deletions.
122 changes: 118 additions & 4 deletions packages/driver/test/connection-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,27 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: false,
fromEnv: false,
},
// fromEnv: true - should take into account env vars
{
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,13 +513,14 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: false,
fromEnv: true,
},
// fromEnv: false - should not take into account env vars
{
opts: { dsn: "edgedb://", user: "user" },
env: {
GEL_DATABASE: "testdb",
GEL_PASSWORD: "passw",
GEL_HOST: "host",
GEL_PORT: "123",
EDGEDB_DATABASE: "testdb",
EDGEDB_PASSWORD: "passw",
EDGEDB_HOST: "host",
EDGEDB_PORT: "123",
},
result: {
...defaults,
Expand Down Expand Up @@ -526,6 +548,40 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: false,
fromEnv: false,
},
// Considers credentials file, environment variables, and inline options in
// order of precedence: credentials file < environment variables < inline
// options, where each level overrides the one before it.
{
opts: { user: "user" },
env: {
EDGEDB_DATABASE: "testdb",
EDGEDB_PASSWORD: "passw",
},
fs: {
cwd: "/home/edgedb/test",
homedir: "/home/edgedb",
files: {
"/home/edgedb/test/edgedb.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 +613,39 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: true,
fromEnv: true,
},
// Considers credentials file and inline options. Inline options
// have higher precedence and ovverride config from the file.
{
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/edgedb.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 +677,29 @@ test("logging, inProject, fromProject, fromEnv", async () => {
fromProject: true,
fromEnv: false,
},
// Considers inline options only. Config from the file and env vars is ignored.
{
opts: { host: "test.local" },
env: {
EDGEDB_DATABASE: "testdb",
EDGEDB_PASSWORD: "passw",
},
fs: {
cwd: "/home/edgedb/test",
homedir: "/home/edgedb",
files: {
"/home/edgedb/test/edgedb.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 +754,8 @@ test("logging, inProject, fromProject, fromEnv", async () => {
}
});

// Checks if _tlsSecurity is correctly set up based on env vars and inline
// options for CLIENT_SECURITY and CLIENT_TLS_SECURITY.
test("GEL_CLIENT_SECURITY env var", async () => {
const truthTable: [string, string, string | null][] = [
// CLIENT_SECURITY, CLIENT_TLS_SECURITY, result
Expand Down
3 changes: 1 addition & 2 deletions packages/driver/test/testUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ export const getServerCommand = (
strictSecurity = true,
): { args: string[]; availableFeatures: string[] } => {
const availableFeatures: string[] = [];
const srvcmd =
process.env.GEL_SERVER_BIN || process.env.EDGEDB_SERVER_BIN || "gel-server";
const srvcmd = process.env.GEL_SERVER_BIN || "gel-server";

let args = [srvcmd];
if (process.platform === "win32") {
Expand Down

0 comments on commit d6c17a7

Please sign in to comment.