Skip to content

Commit

Permalink
Use homedir provided by the container (#436)
Browse files Browse the repository at this point in the history
* Containerize file paths

* suggestions

* fix test-homedir path
  • Loading branch information
ptpaterson authored Nov 26, 2024
1 parent 347bd5d commit 25615ca
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/lib/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const ini = require("ini");
import { Secret } from "../secret";
import { Environment, ProjectConfig } from "./project-config";
import { Endpoint, RootConfig } from "./root-config";
import { container } from "../../cli.mjs";

export { Endpoint, Environment, ProjectConfig, RootConfig };

Expand Down Expand Up @@ -381,7 +382,8 @@ const readFile = (fileName: string) => {
};

export const getRootConfigPath = () => {
return path.join(os.homedir(), ".fauna-shell");
const homedir = container.resolve("homedir");
return path.join(homedir.toString(), ".fauna-shell");
};

export const getProjectConfigPath = (start?: string): string | undefined => {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/file-util.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//@ts-check

import fs from "node:fs";
import os from "node:os";
import path from "node:path";

import { container } from "../cli.mjs";

Expand Down Expand Up @@ -105,7 +105,10 @@ export class Credentials {
constructor(filename = "") {
this.logger = container.resolve("logger");
this.filename = filename;
this.credsDir = `${os.homedir()}/.fauna/credentials`;

const homedir = container.resolve("homedir");
this.credsDir = path.join(homedir.toString(),".fauna/credentials");

if (!dirExists(this.credsDir)) {
fs.mkdirSync(this.credsDir, { recursive: true });
}
Expand Down
7 changes: 7 additions & 0 deletions test/authNZ.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//@ts-check
import path from "node:path";

import * as awilix from "awilix";
import { expect } from "chai";
import { beforeEach } from "mocha";
Expand Down Expand Up @@ -28,9 +31,13 @@ describe.skip("authNZMiddleware", function () {
};

beforeEach(() => {
const __dirname = import.meta.dirname;
const homedir = path.join(__dirname, "./test-homedir");

container = setupContainer();
container.register({
accountClient: awilix.asFunction(mockAccountClient).scoped(),
homedir: awilix.asFunction(() => homedir).scoped(),
});
fetch = container.resolve("fetch");
});
Expand Down
6 changes: 6 additions & 0 deletions test/login.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//@ts-check
import path from "node:path";

import * as awilix from "awilix";
import { expect } from "chai";
Expand Down Expand Up @@ -60,12 +61,17 @@ describe("login", function () {
getToken: stub().resolves({ accessToken: "access-token" }),
};
};

beforeEach(() => {
const __dirname = import.meta.dirname;
const homedir = path.join(__dirname, "./test-homedir");

container = setupContainer();
container.register({
oauthClient: awilix.asFunction(mockOAuth).scoped(),
accountClient: awilix.asFunction(mockAccountClient).scoped(),
accountCreds: awilix.asClass(AccountKey).scoped(),
homedir: awilix.asFunction(() => homedir).scoped(),
});
fs = container.resolve("fs");
});
Expand Down

0 comments on commit 25615ca

Please sign in to comment.