Skip to content

Commit

Permalink
chore: add IPC acceptance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CatalinSnyk committed Mar 10, 2025
1 parent 591cc71 commit 5a74669
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cliv2/internal/cliv2/cliv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ func (c *CLI) executeV1Default(proxyInfo *proxy.ProxyInfo, passThroughArgs []str

func (c *CLI) getErrorFromFile(errFilePath string) (data error, err error) {
bytes, fileErr := os.ReadFile(errFilePath)
if os.IsNotExist(fileErr) {
c.DebugLogger.Println("No data was sent through the IPC file.")
return nil, fileErr
}

if fileErr != nil {
c.DebugLogger.Println("Failed to read error file: ", fileErr)
return nil, fileErr
Expand Down
72 changes: 72 additions & 0 deletions test/jest/acceptance/ipc.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { runSnykCLI } from '../util/runSnykCLI';

describe('the IPC', () => {
const env = {
...process.env,
};

describe('does not sends errors', () => {
it('for successful runs', async () => {
const { code, stderr } = await runSnykCLI(
`test --print-graph ./test/fixtures/npm/with-vulnerable-lodash-dep -d`,
{
env,
},
);

expect(code).toEqual(0);
expect(stderr).not.toContain('Error file contained ');
});

it('when vulnerabilities are found', async () => {
const { code, stderr } = await runSnykCLI(`test semver@2 -d`, {
env,
});

expect(code).toEqual(1);
expect(stderr).not.toContain('No data was sent through the IPC file.');
expect(stderr).not.toContain('Error file contained ');
});

it('for sarif output', async () => {
const { code, stderr } = await runSnykCLI(
`test ./test/fixtures/empty --sarif -d`,
{
env,
},
);

// For exit code 2 we will check the IPC file
expect(code).toEqual(2);
expect(stderr).toContain('No data was sent through the IPC file.');
expect(stderr).not.toContain('Error file contained ');
});
});

describe('sends and receives errors', () => {
it('for no supported files found', async () => {
const { code, stdout, stderr } = await runSnykCLI(
`test ./test/fixtures/empty -d`,
{
env,
},
);

expect(code).toEqual(3);
expect(stdout).toContain('SNYK-CLI-0000');
expect(stderr).toContain('SNYK-CLI-0000');
expect(stderr).toContain('Error file contained ');
});

it('for errors thrown', async () => {
const { code, stdout, stderr } = await runSnykCLI(`test ./not_here -d`, {
env,
});

expect(code).toEqual(2);
expect(stdout).toContain('SNYK-CLI-0000');
expect(stderr).toContain('SNYK-CLI-0000');
expect(stderr).toContain('Error file contained ');
});
});
});

0 comments on commit 5a74669

Please sign in to comment.