-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check that wallet directory exists on file system store creation (#13)
- Change the API to export just the newFileSystemWalletStore factory function. - newFileSystemWalletStore is now async to enable async I/O. - Code example in README updated to reflect current API. Signed-off-by: Mark S. Lewis <[email protected]>
- Loading branch information
1 parent
56d87c1
commit 9690bb9
Showing
10 changed files
with
70 additions
and
42 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
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
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
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
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
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
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
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
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,29 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import fs = require("fs"); | ||
import util = require("util"); | ||
import path = require("path"); | ||
import os = require("os"); | ||
import _rimraf = require("rimraf"); | ||
const rimraf = util.promisify(_rimraf); | ||
|
||
export async function readFile(fileName: string): Promise<string> { | ||
const filePath = path.resolve(__dirname, fileName); | ||
const buffer = await fs.promises.readFile(filePath); | ||
return buffer.toString("utf8"); | ||
} | ||
|
||
export function stripNewlines(text: string): string { | ||
return text.replace(/[\r\n]/g, ""); | ||
} | ||
|
||
export async function createTempDir(): Promise<string> { | ||
const prefix = path.join(os.tmpdir() + path.sep); | ||
return await fs.promises.mkdtemp(prefix); | ||
} | ||
|
||
export async function rmdir(path: string): Promise<void> { | ||
await rimraf(path); | ||
} |
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,17 @@ | ||
/** | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { newFileSystemWalletStore } from "../src/WalletStores"; | ||
import { createTempDir, rmdir } from "./TestUtils"; | ||
|
||
describe("WalletStores", () => { | ||
it("throws if file system wallet directory does not exist", async () => { | ||
const dir = await createTempDir(); | ||
await rmdir(dir); | ||
|
||
const f = newFileSystemWalletStore(dir); | ||
|
||
await expect(f).rejects.toThrow(dir); | ||
}); | ||
}); |