Skip to content

Commit

Permalink
chore: enable endpoint configuration for smoke tests
Browse files Browse the repository at this point in the history
* chore: add TEST_SNYK_API env var

* chore: unify test parametrization TEST_*

* chore: fix typo

* chore: forward env vars to docker container
  • Loading branch information
PeterSchafer authored Jan 30, 2024
1 parent 59c99f6 commit 49696b4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ jobs:
if: ${{ matrix.snyk_install_method == 'alpine-binary' }}
env:
TEST_SNYK_TOKEN: ${{ secrets.TEST_SNYK_TOKEN }}
TEST_SNYK_API: ${{ secrets.TEST_SNYK_API }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
docker build -t snyk-cli-alpine -f ./test/smoke/alpine/Dockerfile ./test
docker run -eCI=1 -eTEST_SNYK_TOKEN -eGITHUB_TOKEN snyk-cli-alpine
docker run -eCI=1 -eTEST_SNYK_TOKEN -eGITHUB_TOKEN -eTEST_SNYK_API snyk-cli-alpine
- name: Install snyk from Docker bundle
if: ${{ matrix.snyk_install_method == 'docker-bundle' && matrix.os == 'macos' }}
Expand All @@ -109,9 +110,10 @@ jobs:
if: ${{ matrix.snyk_install_method == 'npm-root-user' }}
env:
TEST_SNYK_TOKEN: ${{ secrets.TEST_SNYK_TOKEN }}
TEST_SNYK_API: ${{ secrets.TEST_SNYK_API }}
run: |
docker build -t snyk-docker-root -f ./test/smoke/docker-root/Dockerfile ./test
docker run -eCI=1 -eTEST_SNYK_TOKEN snyk-docker-root
docker run -eCI=1 -eTEST_SNYK_TOKEN -eTEST_SNYK_API snyk-docker-root
- name: Install Snyk with binary - Non-Windows
if: ${{ matrix.snyk_install_method == 'binary' && matrix.os != 'windows' }}
Expand Down Expand Up @@ -182,6 +184,7 @@ jobs:
shell: bash -l {0} # run bash with --login flag to load .bash_profile that's used by yarn install method
env:
TEST_SNYK_TOKEN: ${{ secrets.TEST_SNYK_TOKEN }}
TEST_SNYK_API: ${{ secrets.TEST_SNYK_API }}
run: |
which snyk
snyk version
Expand All @@ -193,5 +196,6 @@ jobs:
shell: powershell
env:
TEST_SNYK_TOKEN: ${{ secrets.TEST_SNYK_TOKEN }}
TEST_SNYK_API: ${{ secrets.TEST_SNYK_API }}
run: |
sh ./run-shellspec-win.sh
2 changes: 1 addition & 1 deletion scripts/run-smoke-tests-locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ fi
echo "Installing fixture project with npm install"
npm install --silent --prefix test/fixtures/basic-npm

SNYK_COMMAND="node ${PWD}/bin/snyk" REGRESSION_TEST=1 SMOKE_TESTS_SKIP_TEST_THAT_OPENS_BROWSER=1 TEST_SNYK_TOKEN=$SNYK_API_TOKEN shellspec --chdir test/smoke test/smoke/spec/snyk_auth_spec.sh -f d
TEST_SNYK_COMMAND="node ${PWD}/bin/snyk" REGRESSION_TEST=1 SMOKE_TESTS_SKIP_TEST_THAT_OPENS_BROWSER=1 TEST_SNYK_TOKEN=$SNYK_API_TOKEN shellspec --chdir test/smoke test/smoke/spec/snyk_auth_spec.sh -f d
2 changes: 1 addition & 1 deletion test/smoke/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ npm run test:smoke

`REGRESSION_TEST=1` enables the extended mode we use for regression testing. For the hourly tests in GitHub Actions we use a limited scope of tested commands.

You may specify an envvar `SNYK_COMMAND` to any executable that will be used by Smoke tests. E.g. a local exuctable `SNYK_COMMAND="./snyk-macos"` or an `SNYK_COMMAND="npx snyk@1.500.0"` or `SNYK_COMMAND="node ./dist/cli"` for local execution.
You may specify an envvar `TEST_SNYK_COMMAND` to any executable that will be used by Smoke tests. E.g. a local exuctable `SNYK_COMMAND="./snyk-macos"` or an `SNYK_COMMAND="npx snyk@1.500.0"` or `SNYK_COMMAND="node ./dist/cli"` for local execution.

This will meddle with your `snyk config` file as Smoke Tests are checking functionality of `snyk config` command.

Expand Down
2 changes: 1 addition & 1 deletion test/smoke/spec/sanity_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

Describe "Snyk CLI"
It "have Snyk CLI available"
When run which snyk
When run ${TEST_SNYK_COMMAND} --help
The output should include "/snyk"
The status should be success
The stderr should equal ""
Expand Down
16 changes: 11 additions & 5 deletions test/smoke/spec/spec_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,19 @@ spec_helper_configure() {
╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚══════╝
"

echo "Using this 'snyk' executable:"
echo "${SNYK_COMMAND:=$ORIGINAL_SNYK_EXECUTABLE}"
echo " "
echo "You may override it with envvar SNYK_COMMAND - e.g. SNYK_COMMAND=\"node ./bin/snyk\" to test a local build"
echo "------------------------------------------------------------------------------------------------------"
echo " Binary under test [TEST_SNYK_COMMAND] ............ ${TEST_SNYK_COMMAND:=$ORIGINAL_SNYK_EXECUTABLE}"
echo " API Endpoint [TEST_SNYK_API] ................ ${TEST_SNYK_API}"
echo " Token [TEST_SNYK_TOKEN] .............. ***"
echo "------------------------------------------------------------------------------------------------------"
echo " "

# ensure a clean test environment
unset SNYK_API
unset SNYK_API_KEY
export SNYK_API=${TEST_SNYK_API}

snyk() {
eval "${SNYK_COMMAND:=$ORIGINAL_SNYK_EXECUTABLE}" "$@"
eval "${TEST_SNYK_COMMAND:=$ORIGINAL_SNYK_EXECUTABLE}" "$@"
}
}

0 comments on commit 49696b4

Please sign in to comment.