Skip to content

Commit

Permalink
Merge pull request #26 from snyk-labs/fix/snyk_description_on_helm_ou…
Browse files Browse the repository at this point in the history
…tput

Fix/snyk description on helm output
  • Loading branch information
garethr authored Nov 11, 2019
2 parents ae51f28 + fda4155 commit 687fe3c
Show file tree
Hide file tree
Showing 6 changed files with 443 additions and 91 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
node_modules
dist
.eslintcache
bin
4 changes: 2 additions & 2 deletions plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: "snyk"
version: "1.2.1"
usage: "Snyk Test Docker Images in Helm Charts"
usage: "Check images in your charts for vulnerabilities"
description: |-
"Test your Helm Charts' Docker images with Snyk"
"Test your helm charts' docker images with Snyk"
command: "$HELM_PLUGIN_DIR/scripts/run.sh"

hooks:
Expand Down
73 changes: 50 additions & 23 deletions src/__tests__/test-cli-args.ts
Original file line number Diff line number Diff line change
@@ -1,42 +1,69 @@
import { IArgs, parseInputParameters } from "../cli-args";

test("handles dot or actual path as input", () => {
let inputArgs = ["."];
let parsedArgs: IArgs = parseInputParameters(inputArgs);
expect(parsedArgs.inputDirectory).toBe(".");
expect(parsedArgs.debug).toBe(false);
describe("test command", () => {
describe("check required input directory", () => {
test("process exit if there is no <chart-directory> required arg", () => {
const inputArgs = ["test"];
//@ts-ignore
const mockProcessExit = jest.spyOn(process, "exit").mockImplementation(code => {});

parseInputParameters(inputArgs);
expect(mockProcessExit).toHaveBeenCalledWith(1);
mockProcessExit.mockRestore();
});

test("handles dot as input", () => {
const inputArgs = ["test", "."];

const parsedArgs = parseInputParameters(inputArgs);

expect(parsedArgs.inputDirectory).toBe(".");
expect(parsedArgs.debug).toBe(false);
});

test("handle absolute path as input", () => {
const inputArgs = ["test", "/some/other/path"];
const parsedArgs = parseInputParameters(inputArgs);

expect(parsedArgs.inputDirectory).toBe("/some/other/path");

expect(parsedArgs.debug).toBe(false);
});

inputArgs = ["/some/other/path"];
parsedArgs = parseInputParameters(inputArgs);
expect(parsedArgs.inputDirectory).toBe("/some/other/path");
expect(parsedArgs.debug).toBe(false);
test("handle relative path as input", () => {
const inputArgs = ["test", "~/other/path"];

inputArgs = ["~/other/path"];
parsedArgs = parseInputParameters(inputArgs);
expect(parsedArgs.inputDirectory).toBe("~/other/path");
expect(parsedArgs.debug).toBe(false);
const parsedArgs = parseInputParameters(inputArgs);

expect(parsedArgs.inputDirectory).toBe("~/other/path");
expect(parsedArgs.debug).toBe(false);
});
});
});

test("yargs causes process exit if no args", () => {
//@ts-ignore
const mockProcessExit = jest.spyOn(process, "exit").mockImplementation(code => {});
const inputArgs = [];
const parsedArgs = parseInputParameters(inputArgs);

parseInputParameters(inputArgs);
expect(mockProcessExit).toHaveBeenCalledWith(1);
mockProcessExit.mockRestore();
});

test("handles debug flag", () => {
let inputArgs = [".", "--debug"];
let parsedArgs: IArgs = parseInputParameters(inputArgs);
const inputArgs = ["test", ".", "--debug"];
const parsedArgs: IArgs = parseInputParameters(inputArgs);
expect(parsedArgs.inputDirectory).toBe(".");
expect(parsedArgs.debug).toBe(true);
});

inputArgs = [
".",
"-d" // make sure it works with the short form '-d', too
];
parsedArgs = parseInputParameters(inputArgs);
expect(parsedArgs.inputDirectory).toBe(".");
expect(parsedArgs.debug).toBe(true);
describe("Handle json flag", () => {
test("option --json", () => {
const inputArgs = ["test", ".", "--json"];

const parsedArgs: IArgs = parseInputParameters(inputArgs);

expect(parsedArgs.json).toBeTruthy();
});
});
Loading

0 comments on commit 687fe3c

Please sign in to comment.