Skip to content

Commit

Permalink
test: assert exact errors for unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
lili2311 committed Mar 30, 2021
1 parent 77e6665 commit 3d872fb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/cli/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface ModeData {

const modes: Record<string, ModeData> = {
source: {
allowedCommands: ['test', 'monitor', 'fix'],
allowedCommands: ['test', 'monitor'],
config: (args): [] => {
args['source'] = true;
return args;
Expand Down
7 changes: 3 additions & 4 deletions test/cli-fix.functional.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import * as fs from 'fs';

import cli = require('../src/cli/commands');
import * as snyk from '../src/lib';

import * as validateFixSupported from '../src/cli/commands/fix/validate-fix-command-is-supported';
import * as featureFlags from '../src/lib/feature-flags';

import stripAnsi from 'strip-ansi';

Expand Down Expand Up @@ -49,8 +48,8 @@ const pipWithRemediation = JSON.parse(
describe('snyk fix (functional tests)', () => {
beforeAll(async () => {
jest
.spyOn(validateFixSupported, 'validateFixCommandIsSupported')
.mockResolvedValue(true);
.spyOn(featureFlags, 'isFeatureFlagSupportedForOrg')
.mockResolvedValue({ ok: true });
});

afterAll(async () => {
Expand Down
26 changes: 0 additions & 26 deletions test/cli-fix.system.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,32 +143,6 @@ describe('snyk fix (system tests)', () => {
testTimeout,
);

/* this command is different
* it shows help text not an error when command is not supported
*/
it.skip(
'`shows error when called with container`',
(done) => {
exec(
`node ${main} container fix`,
{
env: {
PATH: process.env.PATH,
SNYK_TOKEN: apiKey,
SNYK_API,
SNYK_HOST,
},
},
(err, stdout, stderr) => {
expect(stderr).toBe('');
expect(stdout).toMatch('COMMANDS');
expect(err).toBe(null);
done();
},
);
},
testTimeout,
);
it(
'`shows error when called with --code`',
(done) => {
Expand Down
18 changes: 14 additions & 4 deletions test/validate-fix-command-is-supported.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { validateFixCommandIsSupported } from '../src/cli/commands/fix/validate-fix-command-is-supported';
import { CommandNotSupportedError } from '../src/lib/errors/command-not-supported';
import { FeatureNotSupportedByEcosystemError } from '../src/lib/errors/not-supported-by-ecosystem';
import * as featureFlags from '../src/lib/feature-flags';
import { ShowVulnPaths } from '../src/lib/types';
describe('setDefaultTestOptions', () => {
Expand All @@ -19,7 +21,9 @@ describe('setDefaultTestOptions', () => {
.spyOn(featureFlags, 'isFeatureFlagSupportedForOrg')
.mockResolvedValue({ ok: false });
const options = { path: '/', showVulnPaths: 'all' as ShowVulnPaths };
expect(validateFixCommandIsSupported(options)).rejects.toThrowError('');
expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
new CommandNotSupportedError('snyk fix', undefined),
);
});

it('fix is NOT supported for --source + enabled FF', () => {
Expand All @@ -31,7 +35,9 @@ describe('setDefaultTestOptions', () => {
showVulnPaths: 'all' as ShowVulnPaths,
source: true,
};
expect(validateFixCommandIsSupported(options)).rejects.toThrowError('');
expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
new FeatureNotSupportedByEcosystemError('snyk fix', 'cpp'),
);
});

it('fix is NOT supported for --docker + enabled FF', () => {
Expand All @@ -43,7 +49,9 @@ describe('setDefaultTestOptions', () => {
showVulnPaths: 'all' as ShowVulnPaths,
docker: true,
};
expect(validateFixCommandIsSupported(options)).rejects.toThrowError('');
expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
new FeatureNotSupportedByEcosystemError('snyk fix', 'docker'),
);
});

it('fix is NOT supported for --code + enabled FF', () => {
Expand All @@ -55,6 +63,8 @@ describe('setDefaultTestOptions', () => {
showVulnPaths: 'all' as ShowVulnPaths,
code: true,
};
expect(validateFixCommandIsSupported(options)).rejects.toThrowError('');
expect(validateFixCommandIsSupported(options)).rejects.toThrowError(
new FeatureNotSupportedByEcosystemError('snyk fix', 'code'),
);
});
});

0 comments on commit 3d872fb

Please sign in to comment.