Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Added tests for IaC JSON test output #3488

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions test/jest/acceptance/iac/output/json.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as fs from 'fs';

import { FakeServer } from '../../../../acceptance/fake-server';
import { isValidJSONString, startMockServer } from '../helpers';

jest.setTimeout(1_000 * 30);

describe('iac test text output', () => {
let server: FakeServer;
let run: (
cmd: string,
overrides?: Record<string, string>,
) => Promise<{ stdout: string; stderr: string; exitCode: number }>;
let teardown: () => Promise<unknown>;

beforeAll(async () => {
({ server, run, teardown } = await startMockServer());
});

afterEach(() => {
server.restore();
});

afterAll(async () => {
await teardown();
});

describe(`with the --json flag`, () => {
describe('with a single file', () => {
const jsonOutputForFile = JSON.parse(fs.readFileSync('../../../../fixtures/iac/test-output/json-output-for-file.json', 'utf-8'))
it('should output the expected results', async () => {
// Arrange
const filePath = 'iac/cloudformation/aurora-valid.yml'

// Act
const { stdout } = await run(`snyk iac test --json ${filePath}`)
const outputJson = JSON.parse(stdout);

// Assert
expect(outputJson).toStrictEqual(jsonOutputForFile)
})
})

describe('with multiple files', () => {
const jsonOutputForFile = JSON.parse(fs.readFileSync('../../../../fixtures/iac/test-output/json-output-for-dir.json', 'utf-8'))

it('should output the expected results', async () => {
// Arrange
const dirPath = 'iac/cloudformation'

// Act
const { stdout } = await run(`snyk iac test --json ${dirPath}`)
const outputJson = JSON.parse(stdout);

// Assert
expect(outputJson).toStrictEqual(jsonOutputForFile)
})
})
})
});
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import * as fs from 'fs';
import chalk from 'chalk';
import { EOL } from 'os';
import * as pathLib from 'path';
import {
spinnerMessage,
spinnerSuccessMessage,
} from '../../../../src/lib/formatters/iac-output';
} from '../../../../../src/lib/formatters/iac-output';

import { FakeServer } from '../../../acceptance/fake-server';
import { isValidJSONString, startMockServer } from './helpers';
import { FakeServer } from '../../../../acceptance/fake-server';
import { isValidJSONString, startMockServer } from '../helpers';

const IAC_CLI_OUTPUT_FF = 'iacCliOutputRelease';

jest.setTimeout(1000 * 30);

describe('iac test output', () => {
describe('iac test text output', () => {
let server: FakeServer;
let run: (
cmd: string,
Expand Down Expand Up @@ -476,4 +477,5 @@ https://support.snyk.io/hc/en-us/articles/360013723877-Test-your-Terraform-files
});
});
});
});

});