Skip to content

Commit

Permalink
feat: support project name option in test command
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Holdcroft committed Jul 22, 2019
1 parent 2caf59b commit 3fbf139
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
2 changes: 1 addition & 1 deletion help/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Options:
dependencies, down to the vulnerable packages (defaults
to true). Applicable to `snyk test`.
--project-name=<string>
Specify a custom Snyk project name (`snyk monitor` only).
Specify a custom Snyk project name.
--policy-path ...... Manually pass a path to a policy file.
--insecure ......... Ignore unknown certificate authorities.
--json ............. Return results in JSON format.
Expand Down
1 change: 1 addition & 0 deletions src/cli/commands/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ async function test(...args: MethodArgs): Promise<string> {
// these options later.
const testOpts = _.cloneDeep(options);
testOpts.path = path;
testOpts.projectName = testOpts['project-name'];

let res;

Expand Down
50 changes: 43 additions & 7 deletions test/acceptance/cli.acceptance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ test('`test sinatra --registry=rubygems` sends remote Rubygems request:', async
* Local source `test`
*/

test('`test project with custom --project-name`', async (t) => {
chdirWorkspaces();
await cli.test('project', {
'project-name': 'custom-project-name',
});
const req = server.popRequest();
t.equal(req.body.projectNameOverride, 'custom-project-name');
});

test('`test empty --file=Gemfile`', async (t) => {
chdirWorkspaces();
try {
Expand Down Expand Up @@ -742,6 +751,7 @@ test('`test nuget-app-2 auto-detects project.assets.json`', async (t) => {
args: null,
file: 'project.assets.json',
org: null,
projectName: null,
packageManager: 'nuget',
path: 'nuget-app-2',
showVulnPaths: true,
Expand Down Expand Up @@ -780,6 +790,7 @@ test('`test nuget-app-2.1 auto-detects obj/project.assets.json`', async (t) => {
args: null,
file: 'obj/project.assets.json',
org: null,
projectName: null,
packageManager: 'nuget',
path: 'nuget-app-2.1',
showVulnPaths: true,
Expand Down Expand Up @@ -819,6 +830,7 @@ test('`test nuget-app-4 auto-detects packages.config`', async (t) => {
args: null,
file: 'packages.config',
org: null,
projectName: null,
packageManager: 'nuget',
path: 'nuget-app-4',
showVulnPaths: true,
Expand Down Expand Up @@ -858,6 +870,7 @@ test('`test paket-app auto-detects paket.dependencies`', async (t) => {
args: null,
file: 'paket.dependencies',
org: null,
projectName: null,
packageManager: 'paket',
path: 'paket-app',
showVulnPaths: true,
Expand Down Expand Up @@ -897,6 +910,7 @@ test('`test paket-obj-app auto-detects obj/project.assets.json if exists`', asyn
args: null,
file: 'obj/project.assets.json',
org: null,
projectName: null,
packageManager: 'nuget',
path: 'paket-obj-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1175,6 +1189,7 @@ test('`test pip-app --file=requirements.txt`', async (t) => {
args: null,
file: 'requirements.txt',
org: null,
projectName: null,
packageManager: 'pip',
path: 'pip-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1216,6 +1231,7 @@ test('`test pipenv-app --file=Pipfile`', async (t) => {
args: null,
file: 'Pipfile',
org: null,
projectName: null,
packageManager: 'pip',
path: 'pipenv-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1257,6 +1273,7 @@ test('`test nuget-app --file=project.assets.json`', async (t) => {
args: null,
file: 'project.assets.json',
org: null,
projectName: null,
packageManager: 'nuget',
path: 'nuget-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1298,6 +1315,7 @@ test('`test nuget-app --file=packages.config`', async (t) => {
args: null,
file: 'packages.config',
org: null,
projectName: null,
packageManager: 'nuget',
path: 'nuget-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1332,6 +1350,7 @@ test('`test nuget-app --file=project.json`', async (t) => {
args: null,
file: 'project.json',
org: null,
projectName: null,
packageManager: 'nuget',
path: 'nuget-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1373,6 +1392,7 @@ test('`test paket-app --file=paket.dependencies`', async (t) => {
args: null,
file: 'paket.dependencies',
org: null,
projectName: null,
packageManager: 'paket',
path: 'paket-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1407,6 +1427,7 @@ test('`test golang-gomodules --file=go.mod`', async (t) => {
args: null,
file: 'go.mod',
org: null,
projectName: null,
packageManager: 'gomodules',
path: 'golang-gomodules',
showVulnPaths: true,
Expand Down Expand Up @@ -1439,6 +1460,7 @@ test('`test golang-app` auto-detects golang-gomodules', async (t) => {
args: null,
file: 'go.mod',
org: null,
projectName: null,
packageManager: 'gomodules',
path: 'golang-gomodules',
showVulnPaths: true,
Expand Down Expand Up @@ -1473,6 +1495,7 @@ test('`test golang-app --file=Gopkg.lock`', async (t) => {
args: null,
file: 'Gopkg.lock',
org: null,
projectName: null,
packageManager: 'golangdep',
path: 'golang-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1507,6 +1530,7 @@ test('`test golang-app --file=vendor/vendor.json`', async (t) => {
args: null,
file: 'vendor/vendor.json',
org: null,
projectName: null,
packageManager: 'govendor',
path: 'golang-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1539,6 +1563,7 @@ test('`test golang-app` auto-detects golang/dep', async (t) => {
args: null,
file: 'Gopkg.lock',
org: null,
projectName: null,
packageManager: 'golangdep',
path: 'golang-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1570,6 +1595,7 @@ test('`test golang-app-govendor` auto-detects govendor', async (t) => {
args: null,
file: 'vendor/vendor.json',
org: null,
projectName: null,
packageManager: 'govendor',
path: 'golang-app-govendor',
showVulnPaths: true,
Expand Down Expand Up @@ -1603,6 +1629,7 @@ test('`test composer-app --file=composer.lock`', async (t) => {
args: null,
file: 'composer.lock',
org: null,
projectName: null,
packageManager: 'composer',
path: 'composer-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1634,6 +1661,7 @@ test('`test composer-app` auto-detects composer.lock', async (t) => {
args: null,
file: 'composer.lock',
org: null,
projectName: null,
packageManager: 'composer',
path: 'composer-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1683,6 +1711,7 @@ test('`test composer-app golang-app nuget-app` auto-detects all three projects',
args: null,
org: 'test-org',
file: 'composer.lock',
projectName: null,
packageManager: 'composer',
path: 'composer-app',
showVulnPaths: true,
Expand All @@ -1692,6 +1721,7 @@ test('`test composer-app golang-app nuget-app` auto-detects all three projects',
args: null,
org: 'test-org',
file: 'Gopkg.lock',
projectName: null,
packageManager: 'golangdep',
path: 'golang-app',
showVulnPaths: true,
Expand All @@ -1701,6 +1731,7 @@ test('`test composer-app golang-app nuget-app` auto-detects all three projects',
args: null,
org: 'test-org',
file: 'project.assets.json',
projectName: null,
packageManager: 'nuget',
path: 'nuget-app',
showVulnPaths: true,
Expand Down Expand Up @@ -1729,6 +1760,7 @@ test('`test foo:latest --docker`', async (t) => {
file: null,
docker: true,
org: 'explicit-org',
projectName: null,
packageManager: null,
path: 'foo:latest',
showVulnPaths: true,
Expand Down Expand Up @@ -1807,6 +1839,7 @@ test('`test foo:latest --docker --file=Dockerfile`', async (t) => {
file: 'Dockerfile',
docker: true,
org: 'explicit-org',
projectName: null,
packageManager: null,
path: 'foo:latest',
showVulnPaths: true,
Expand Down Expand Up @@ -1855,6 +1888,7 @@ test('`test foo:latest --docker` doesnt collect policy from cwd', async (t) => {
file: null,
docker: true,
org: 'explicit-org',
projectName: null,
packageManager: null,
path: 'foo:latest',
showVulnPaths: true,
Expand Down Expand Up @@ -1882,13 +1916,14 @@ test('`test foo:latest --docker` supports custom policy', async (t) => {
t.equal(req.body.depGraph.pkgManager.name, 'deb');
t.same(spyPlugin.getCall(0).args,
['foo:latest', null, {
'args': null,
'file': null,
'docker': true,
'org': 'explicit-org',
'packageManager': null,
'path': 'foo:latest',
'showVulnPaths': true,
args: null,
file: null,
docker: true,
org: 'explicit-org',
projectName: null,
packageManager: null,
path: 'foo:latest',
showVulnPaths: true,
'policy-path': 'npm-package-policy/custom-location',
}], 'calls docker plugin with expected arguments');

Expand Down Expand Up @@ -1927,6 +1962,7 @@ test('`test foo:latest --docker with binaries`', async (t) => {
file: null,
docker: true,
org: 'explicit-org',
projectName: null,
packageManager: null,
path: 'foo:latest',
showVulnPaths: true,
Expand Down

0 comments on commit 3fbf139

Please sign in to comment.