Skip to content

Commit

Permalink
Merge pull request #1855 from snyk/feat/propagate-cli-options
Browse files Browse the repository at this point in the history
feat(@snyk/fix): propagate cli test options
  • Loading branch information
lili2311 committed May 4, 2021
2 parents 12eadfb + d2e7533 commit 634e5f2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/snyk-fix/src/types.ts
Expand Up @@ -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: Original;
error: CustomError;
Expand Down
Expand Up @@ -1243,6 +1243,9 @@ function generateEntityToFix(
testResult: TestResult,
): snykFix.EntityToFix {
const entityToFix = {
options: {
command: 'python3',
},
workspace: {
path: workspacesPath,
readFile: async (path: string) => {
Expand Down
13 changes: 11 additions & 2 deletions 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,
Expand All @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions packages/snyk-fix/test/unit/__snapshots__/fix.spec.ts.snap
Expand Up @@ -6,6 +6,9 @@ Object {
"npm": Object {
"originals": Array [
Object {
"options": Object {
"command": "python3",
},
"scanResult": Object {
"facts": Array [
Object {
Expand Down Expand Up @@ -124,6 +127,9 @@ Summary:
},
],
"original": Object {
"options": Object {
"command": "python3",
},
"scanResult": Object {
"facts": Array [
Object {
Expand Down Expand Up @@ -215,6 +221,9 @@ Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>. If the iss
"skipped": Array [
Object {
"original": Object {
"options": Object {
"command": "python3",
},
"scanResult": Object {
"facts": Array [
Object {
Expand Down Expand Up @@ -282,6 +291,9 @@ Re-run in debug mode to see more information: DEBUG=*snyk* <COMMAND>. If the iss
},
],
"original": Object {
"options": Object {
"command": "python3",
},
"scanResult": Object {
"facts": Array [
Object {
Expand Down Expand Up @@ -360,6 +372,9 @@ Object {
},
],
"original": Object {
"options": Object {
"command": "python3",
},
"scanResult": Object {
"facts": Array [
Object {
Expand Down
1 change: 1 addition & 0 deletions src/lib/types.ts
Expand Up @@ -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 */
Expand Down

0 comments on commit 634e5f2

Please sign in to comment.