Skip to content

Commit e65d1b1

Browse files
committed
chore: updated tests to be more accurate
[ci skip]
1 parent afb4bc4 commit e65d1b1

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/errors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ class ErrorPolykeyCLIDuplicateEnvName<T> extends ErrorPolykeyCLI<T> {
152152
exitCode = sysexits.USAGE;
153153
}
154154

155+
class ErrorPolykeyCLIMakeDirectory<T> extends ErrorPolykeyCLI<T> {
156+
static description = 'Failed to create one or more directories';
157+
exitCode = 1;
158+
}
159+
155160
export {
156161
ErrorPolykeyCLI,
157162
ErrorPolykeyCLIUncaughtException,
@@ -172,4 +177,5 @@ export {
172177
ErrorPolykeyCLINodePingFailed,
173178
ErrorPolykeyCLIInvalidEnvName,
174179
ErrorPolykeyCLIDuplicateEnvName,
180+
ErrorPolykeyCLIMakeDirectory,
175181
};

src/secrets/CommandMkdir.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import * as binUtils from '../utils';
44
import * as binOptions from '../utils/options';
55
import * as binParsers from '../utils/parsers';
66
import * as binProcessors from '../utils/processors';
7-
import { ErrorPolykeyCLIUncaughtException } from '@/errors';
8-
import { utils } from '@';
7+
import {
8+
ErrorPolykeyCLIMakeDirectory,
9+
ErrorPolykeyCLIUncaughtException,
10+
} from '@/errors';
911

1012
class CommandMkdir extends CommandPolykey {
1113
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
@@ -78,9 +80,10 @@ class CommandMkdir extends CommandPolykey {
7880
'WARNING: Empty directories will not be affected by modifications to the vault state (version change, sharing/cloning, etc.)\n',
7981
);
8082

83+
let shouldError = false;
8184
for await (const result of response.readable) {
8285
if (result.type === 'error') {
83-
process.exitCode = 1;
86+
shouldError = true;
8487
let message: string = '';
8588
switch (result.code) {
8689
case 'ENOENT':
@@ -99,6 +102,11 @@ class CommandMkdir extends CommandPolykey {
99102
);
100103
}
101104
}
105+
if (shouldError) {
106+
throw new ErrorPolykeyCLIMakeDirectory(
107+
'Failed to create one or more directories',
108+
);
109+
}
102110
} finally {
103111
if (pkClient! != null) await pkClient.stop();
104112
}

tests/secrets/mkdir.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('commandMkdir', () => {
6767
const vaultName = 'vault' as VaultName;
6868
const dirName1 = 'dir1';
6969
const dirName2 = 'dir2';
70-
const dirNameNested = `${dirName1}/${dirName2}`;
70+
const dirNameNested = path.join(dirName1, dirName2);
7171
const vaultId = await polykeyAgent.vaultManager.createVault(vaultName);
7272
command = [
7373
'secrets',
@@ -93,7 +93,7 @@ describe('commandMkdir', () => {
9393
const vaultName = 'vault' as VaultName;
9494
const dirName1 = 'dir1';
9595
const dirName2 = 'dir2';
96-
const dirNameNested = `${dirName1}/${dirName2}`;
96+
const dirNameNested = path.join(dirName1, dirName2);
9797
const vaultId = await polykeyAgent.vaultManager.createVault(vaultName);
9898
command = [
9999
'secrets',

0 commit comments

Comments
 (0)