From d2e753368c059d353fafbe5f1b08c2f5ab7c3a99 Mon Sep 17 00:00:00 2001 From: ghe Date: Thu, 22 Apr 2021 09:48:55 +0100 Subject: [PATCH] feat(@snyk/fix): propagate cli test options --- packages/snyk-fix/src/types.ts | 9 ++++++++- .../update-dependencies.spec.ts | 3 +++ .../test/helpers/generate-entity-to-fix.ts | 13 +++++++++++-- .../test/unit/__snapshots__/fix.spec.ts.snap | 15 +++++++++++++++ src/lib/types.ts | 1 + 5 files changed, 38 insertions(+), 3 deletions(-) diff --git a/packages/snyk-fix/src/types.ts b/packages/snyk-fix/src/types.ts index 8e470f32e9f..a5d2079761e 100644 --- a/packages/snyk-fix/src/types.ts +++ b/packages/snyk-fix/src/types.ts @@ -185,9 +185,16 @@ export interface EntityToFix { readonly workspace: Workspace; readonly scanResult: ScanResult; readonly testResult: TestResult; - // options + readonly options: CliTestOptions; } +// Partial CLI test options interface +// defining only what is used by @snyk/fix +// add more as needed +export interface PythonTestOptions { + command?: string; // python interpreter to use for python tests +} +export type CliTestOptions = PythonTestOptions; export interface WithError { original: Original; error: CustomError; diff --git a/packages/snyk-fix/test/acceptance/plugins/python/handlers/pip-requirements/update-dependencies/update-dependencies.spec.ts b/packages/snyk-fix/test/acceptance/plugins/python/handlers/pip-requirements/update-dependencies/update-dependencies.spec.ts index 13736bf36fe..3c68e08bce8 100644 --- a/packages/snyk-fix/test/acceptance/plugins/python/handlers/pip-requirements/update-dependencies/update-dependencies.spec.ts +++ b/packages/snyk-fix/test/acceptance/plugins/python/handlers/pip-requirements/update-dependencies/update-dependencies.spec.ts @@ -1243,6 +1243,9 @@ function generateEntityToFix( testResult: TestResult, ): snykFix.EntityToFix { const entityToFix = { + options: { + command: 'python3', + }, workspace: { path: workspacesPath, readFile: async (path: string) => { diff --git a/packages/snyk-fix/test/helpers/generate-entity-to-fix.ts b/packages/snyk-fix/test/helpers/generate-entity-to-fix.ts index f3ef63c7d53..f7d401318e6 100644 --- a/packages/snyk-fix/test/helpers/generate-entity-to-fix.ts +++ b/packages/snyk-fix/test/helpers/generate-entity-to-fix.ts @@ -1,5 +1,11 @@ import { DepGraphData } from '@snyk/dep-graph'; -import { EntityToFix, ScanResult, TestResult, FixInfo, SEVERITY } from '../../src/types'; +import { + EntityToFix, + ScanResult, + TestResult, + FixInfo, + SEVERITY, +} from '../../src/types'; export function generateEntityToFix( type: string, @@ -10,7 +16,10 @@ export function generateEntityToFix( const scanResult = generateScanResult(type, targetFile); const testResult = generateTestResult(); const workspace = generateWorkspace(contents, path); - return { scanResult, testResult, workspace }; + const cliTestOptions = { + command: 'python3', + }; + return { scanResult, testResult, workspace, options: cliTestOptions }; } function generateWorkspace(contents: string, path?: string) { diff --git a/packages/snyk-fix/test/unit/__snapshots__/fix.spec.ts.snap b/packages/snyk-fix/test/unit/__snapshots__/fix.spec.ts.snap index 630bc9ada50..e7e1bc48b13 100644 --- a/packages/snyk-fix/test/unit/__snapshots__/fix.spec.ts.snap +++ b/packages/snyk-fix/test/unit/__snapshots__/fix.spec.ts.snap @@ -6,6 +6,9 @@ Object { "npm": Object { "originals": Array [ Object { + "options": Object { + "command": "python3", + }, "scanResult": Object { "facts": Array [ Object { @@ -124,6 +127,9 @@ Summary: }, ], "original": Object { + "options": Object { + "command": "python3", + }, "scanResult": Object { "facts": Array [ Object { @@ -215,6 +221,9 @@ Re-run in debug mode to see more information: DEBUG=*snyk* . If the iss "skipped": Array [ Object { "original": Object { + "options": Object { + "command": "python3", + }, "scanResult": Object { "facts": Array [ Object { @@ -282,6 +291,9 @@ Re-run in debug mode to see more information: DEBUG=*snyk* . If the iss }, ], "original": Object { + "options": Object { + "command": "python3", + }, "scanResult": Object { "facts": Array [ Object { @@ -360,6 +372,9 @@ Object { }, ], "original": Object { + "options": Object { + "command": "python3", + }, "scanResult": Object { "facts": Array [ Object { diff --git a/src/lib/types.ts b/src/lib/types.ts index d4e5c08b2b8..8371e8fe009 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -21,6 +21,7 @@ export interface TestOptions { reachableVulnsTimeout?: number; initScript?: string; yarnWorkspaces?: boolean; + command?: string; // python interpreter to use for python tests testDepGraphDockerEndpoint?: string | null; isDockerUser?: boolean; /** @deprecated Only used by the legacy `iac test` flow remove once local exec path is GA */