Skip to content

Commit

Permalink
chore: introduce go entry point for snyk code test
Browse files Browse the repository at this point in the history
  • Loading branch information
thisislawatts committed Mar 21, 2024
1 parent 2f3fc5d commit 234dfea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cliv2/cmd/cliv2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func createCommandsForWorkflows(rootCommand *cobra.Command, engine workflow.Engi
parentCommand.Hidden = !workflowEntry.IsVisible()
parentCommand.DisableFlagParsing = false

// special case for snyk code test, since it requires relaxed flag validation
// special case for snyk code test, to preserve backwards compatibility we will need to relax flag validation
if currentCommandString == "code test" {
parentCommand.FParseErrWhitelist.UnknownFlags = true
}
Expand Down Expand Up @@ -382,6 +382,7 @@ func MainWithErrorCode() int {
engine.AddExtensionInitializer(iacrules.Init)
engine.AddExtensionInitializer(snykls.Init)
engine.AddExtensionInitializer(container.Init)
engine.AddExtensionInitializer(localworkflows.InitCodeWorkflow)

// init engine
err = engine.Init()
Expand Down
25 changes: 25 additions & 0 deletions test/jest/acceptance/snyk-code/snyk-code.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { runSnykCLI } from '../../util/runSnykCLI';

describe('code', () => {
it('prints help info', async () => {
const { stdout, code, stderr } = await runSnykCLI('code');

expect(stdout).toContain(
'The snyk code test command finds security issues using Static Code Analysis.',
);
expect(code).toBe(0);
expect(stderr).toBe('');
});

describe('test', () => {
jest.setTimeout(60000);
it('supports unknown flags', async () => {
const { stdout, stderr } = await runSnykCLI('code test --unknown-flag');

// We do not render the help message for unknown flags
expect(stdout).not.toContain('snyk code test [<OPTIONS>] [<PATH>]');
expect(stdout).toContain('Testing ');
expect(stderr).toBe('');
});
});
});

0 comments on commit 234dfea

Please sign in to comment.