Skip to content

Commit

Permalink
feat: remove --json-file-output for snykl iac describe
Browse files Browse the repository at this point in the history
  • Loading branch information
eliecharra committed Mar 30, 2022
1 parent 9fa1420 commit bc04b5e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
5 changes: 0 additions & 5 deletions src/lib/iac/drift.ts
Expand Up @@ -135,11 +135,6 @@ const generateFmtFlags = (options: FmtOptions): string[] => {
args.push('json://stdout');
}

if (options['json-file-output']) {
args.push('--output');
args.push('json://' + options['json-file-output']);
}

if (options.html) {
args.push('--output');
args.push('html://stdout');
Expand Down
2 changes: 0 additions & 2 deletions src/lib/iac/types.d.ts
Expand Up @@ -9,7 +9,6 @@ interface DriftCTLOptions {

export interface FmtOptions extends DriftCTLOptions {
json: boolean;
'json-file-output': string;
html: boolean;
'html-file-output': string;
}
Expand Down Expand Up @@ -38,7 +37,6 @@ export interface DescribeOptions extends DriftCTLOptions {
'tf-lockfile'?: string;
'config-dir'?: string;
json?: boolean;
'json-file-output'?: string;
html?: boolean;
'html-file-output'?: string;
service?: string;
Expand Down
49 changes: 49 additions & 0 deletions test/jest/acceptance/iac/describe.spec.ts
Expand Up @@ -114,6 +114,55 @@ describe('iac describe', () => {
expect(exitCode).toBe(0);
});

describe('Test html file output', () => {
let htmlFile: string;
const fixtureHtmlReport = path.join(
getFixturePath('iac'),
'drift',
'output',
'driftctl_output.html',
);
beforeEach(() => {
htmlFile = path.join(tmpFolderPath, 'foobar.html');
fs.copyFileSync(fixtureHtmlReport, htmlFile);
});
afterEach(() => {
rimraf.sync(htmlFile);
});

it('Launch driftctl with html output format', async () => {
const { stdout, stderr, exitCode } = await run(
`snyk iac describe --all --html-file-output=${htmlFile}`,
{
SNYK_FIXTURE_OUTPUT_PATH: outputFile,
SNYK_DRIFTCTL_PATH: path.join(
getFixturePath('iac'),
'drift',
'args-echo.sh',
),
},
);

expect(stdout).toBe('');
expect(stderr).toBe('');
expect(exitCode).toBe(0);

const output = fs.readFileSync(outputFile).toString();

// First invocation of driftctl scan triggered by describe cmd
expect(output).toContain('DCTL_IS_SNYK=true');
expect(output).toContain(
`ARGS=scan --no-version-check --output json://stdout --config-dir ${paths.cache} --to aws+tf`,
);

// Second invocation of driftctl fmt triggered by describe cmd
// We should test that the format is properly set for fmt command
expect(output).toContain(
`ARGS=fmt --no-version-check --output html://${htmlFile}`,
);
});
});

it('Download and launch driftctl when executable is not found and org has the entitlement', async () => {
const cachedir = path.join(os.tmpdir(), 'driftctl_download_' + Date.now());
const { stderr, exitCode } = await run(`snyk iac describe --all`, {
Expand Down

0 comments on commit bc04b5e

Please sign in to comment.