Skip to content

Commit

Permalink
fix: correct iac error import & add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Jul 28, 2020
1 parent 87151b8 commit efbcf84
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/snyk-test/index.js
Expand Up @@ -7,7 +7,7 @@ const pm = require('../package-managers');
const iacProjects = require('../iac/iac-projects');
const {
UnsupportedPackageManagerError,
NoSupportedIacFileError,
NotSupportedIacFileError,
} = require('../errors');

async function test(root, options, callback) {
Expand Down Expand Up @@ -58,7 +58,7 @@ function run(root, options) {
if (options.iac) {
const projectType = options.packageManager;
if (!iacProjects.TEST_SUPPORTED_IAC_PROJECTS.includes(projectType)) {
throw new NoSupportedIacFileError(projectType);
throw new NotSupportedIacFileError(projectType);
}
return runTest(projectType, root, options);
}
Expand Down
47 changes: 47 additions & 0 deletions test/acceptance/cli-args.test.ts
Expand Up @@ -59,6 +59,53 @@ test('snyk test command should fail when --packageManager is not specified corre
});
});

test('snyk test command should fail when iac file is not specified', (t) => {
t.plan(1);
exec(`node ${main} iac test`, (err, stdout) => {
if (err) {
throw err;
}
t.match(
stdout.trim(),
'iac option works only with specified files',
'correct error output',
);
});
});

test('snyk test command should fail when iac file is not supported', (t) => {
t.plan(1);
exec(
`node ${main} iac test --file=./test/acceptance/workspaces/empty/readme.md`,
(err, stdout) => {
if (err) {
throw err;
}
t.match(
stdout.trim(),
'CustomError: Illegal infrastructure as code target file',
'correct error output',
);
},
);
});

test('snyk test command should fail when iac file is not supported', (t) => {
t.plan(1);
exec(
`node ${main} iac test --file=./test/acceptance/workspaces/helmconfig/Chart.yaml`,
(err, stdout) => {
if (err) {
throw err;
}
t.match(
stdout.trim(),
'CustomError: Not supported infrastructure as code target files in',
'correct error output',
);
},
);
});
test('`test multiple paths with --project-name=NAME`', (t) => {
t.plan(1);
exec(`node ${main} test pathA pathB --project-name=NAME`, (err, stdout) => {
Expand Down
Empty file.

0 comments on commit efbcf84

Please sign in to comment.