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: Test snyk/scan commands with additional-arguments #109

Merged
merged 3 commits into from
Aug 14, 2023
Merged
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
66 changes: 64 additions & 2 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,69 @@ commands:
scan:
description: test the scan functionality
parameters:
fail-on-issues:
type: boolean
default: false
monitor-on-build:
type: boolean
default: false
no-cache:
type: boolean
default: false
additional-arguments:
type: string
default: ''
additional-monitor-arguments:
type: string
default: ''

test-only-param_fail-on-no-cache-used:
type: boolean
default: false
test-only-param_dry-run-commands:
type: boolean
default: false

steps:
- node/install

- run:
name: Setup test repository
command: |
git clone https://github.com/snyk-labs/nodejs-goof || echo "Repository already exists, no cloning needed."
cd nodejs-goof
npm install

- snyk/scan:
fail-on-issues: false
monitor-on-build: false
target-file: nodejs-goof/package.json

fail-on-issues: << parameters.fail-on-issues >>
monitor-on-build: << parameters.monitor-on-build >>
no-cache: << parameters.no-cache >>
additional-arguments: << parameters.additional-arguments >>
additional-monitor-arguments: << parameters.additional-monitor-arguments >>

test-only-param_fail-on-no-cache-used: << parameters.test-only-param_fail-on-no-cache-used >>
test-only-param_dry-run-commands: << parameters.test-only-param_dry-run-commands >>

validate-dry-run-commands:
description: validation hook to test the output of commands run under dry-run mode
parameters:
expected-commands:
type: string
steps:
- run:
name: Compare expected commands
command: >
if [[ "$(cat /tmp/dry-run-snyk-commands.txt)" != "$(printf "<< parameters.expected-commands >>")" ]]; then
echo "Expected Commands ========================================"
printf "<< parameters.expected-commands >>"

echo "Actual Commands =========================================="
cat /tmp/dry-run-snyk-commands.txt

false
fi

jobs:
scan-test:
Expand Down Expand Up @@ -70,6 +113,20 @@ jobs:
- scan:
no-cache: true

scan-test-monitor-additional-arguments:
docker:
- image: cimg/base:current
steps:
- scan:
test-only-param_dry-run-commands: true
additional-arguments: "--print-deps"
additional-monitor-arguments: "--project-tags=component=pkg:github.com/snyk-labs/nodejs-goof"
monitor-on-build: true
- validate-dry-run-commands:
expected-commands: |
snyk test --severity-threshold=low --file=nodejs-goof/package.json --print-deps
snyk monitor --file=nodejs-goof/package.json --print-deps --project-tags=component=pkg:github.com/snyk-labs/nodejs-goof

workflows:
test-deploy:
jobs:
Expand Down Expand Up @@ -97,3 +154,8 @@ workflows:
context:
- hammerhead-snyk-orb-snyk-creds
filters: *filters

- scan-test-monitor-additional-arguments:
context:
- hammerhead-snyk-orb-snyk-creds
filters: *filters
8 changes: 8 additions & 0 deletions src/commands/scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ parameters:
It should not be used in production.
type: boolean
default: false
test-only-param_dry-run-commands:
description: >
This parameter is used to test arguments provided to the snyk commands.
It should not be used in production.
type: boolean
default: false
steps:
# install snyk
- install:
Expand All @@ -98,6 +104,7 @@ steps:
SNYK_INTEGRATION_NAME: CIRCLECI_ORB
SNYK_INTEGRATION_VERSION: REPLACE_ORB_VERSION
command: >
<<#parameters.test-only-param_dry-run-commands>>function capture() { echo "$@" | tee -a /tmp/dry-run-snyk-commands.txt; }; capture<</parameters.test-only-param_dry-run-commands>>
snyk <<parameters.command>>
<<#parameters.docker-image-name>>--docker <<parameters.docker-image-name>><</parameters.docker-image-name>>
<<#parameters.severity-threshold>>--severity-threshold=<<parameters.severity-threshold>><</parameters.severity-threshold>>
Expand All @@ -116,6 +123,7 @@ steps:
SNYK_INTEGRATION_NAME: CIRCLECI_ORB
SNYK_INTEGRATION_VERSION: REPLACE_ORB_VERSION
command: >
<<#parameters.test-only-param_dry-run-commands>>function capture() { echo "$@" | tee -a /tmp/dry-run-snyk-commands.txt; }; capture<</parameters.test-only-param_dry-run-commands>>
snyk monitor
<<#parameters.docker-image-name>>--docker <<parameters.docker-image-name>><</parameters.docker-image-name>>
<<#parameters.project>>--project-name=<<parameters.project>><</parameters.project>>
Expand Down