-
Notifications
You must be signed in to change notification settings - Fork 570
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1767 from snyk/smoke/improve-shellspec
Improve smoke tests dev experience
- Loading branch information
Showing
10 changed files
with
131 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
echo "Attempting to run Smoke Tests locally. See file 'test/smoke/README.md' for details. This will drop your local 'snyk config'!" | ||
|
||
if [ -z "$SNYK_API_TOKEN" ]; then | ||
echo "You need to set 'SNYK_API_TOKEN' envvar." >&2 | ||
exit 1 | ||
fi | ||
|
||
if ! [ -x "$(command -v shellspec)" ]; then | ||
if ! [ -x "$(command -v brew)" ]; then | ||
echo "Error: Shellspec is not installed. See https://shellspec.info for install instructions" >&2 | ||
exit 1 | ||
fi | ||
echo "Installing shellspec with brew" | ||
brew install shellspec | ||
fi | ||
|
||
if ! [ -x "$(command -v jq)" ]; then | ||
if ! [ -x "$(command -v brew)" ]; then | ||
echo "Error: jq is not installed. See https://stedolan.github.io/jq/ for install instructions" >&2 | ||
exit 1 | ||
fi | ||
echo "Installing jq with brew" | ||
brew install jq | ||
fi | ||
|
||
if ! [ -x "$(command -v timeout)" ]; then | ||
if ! [ -x "$(command -v brew)" ]; then | ||
echo "Error: 'timeout' command is not installed." >&2 | ||
exit 1 | ||
fi | ||
echo "Installing coreutils (which contains timeout) with brew" | ||
brew install coreutils | ||
fi | ||
|
||
echo "Installing fixture project with npm install" | ||
npm install --silent --prefix test/fixtures/basic-npm | ||
|
||
SNYK_COMMAND="node ${PWD}/dist/cli" REGRESSION_TEST=1 SMOKE_TESTS_SKIP_TEST_THAT_OPENS_BROWSER=1 SMOKE_TESTS_SNYK_TOKEN=$SNYK_API_TOKEN shellspec --chdir test/smoke test/smoke/spec/snyk_auth_spec.sh -f d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
echo "run-shellscript-win.sh" | ||
|
||
export EXPECTED_SNYK_VERSION=$(snyk --version) | ||
|
||
/c/Users/runneradmin/.local/bin/shellspec -f d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,71 @@ | ||
#shellcheck shell=sh | ||
set -e | ||
|
||
print_snyk_config() { | ||
snyk config | ||
spec_helper_precheck() { | ||
setenv CI=1 # This flag influences behavior of `snyk auth` so it needs to be explicitly set | ||
setenv ORIGINAL_SNYK_EXECUTABLE="$(which snyk)" | ||
} | ||
|
||
snyk_login() { | ||
snyk auth "${SMOKE_TESTS_SNYK_TOKEN}" > /dev/null 2>&1 | ||
} | ||
spec_helper_configure() { | ||
print_snyk_config() { | ||
snyk config | ||
} | ||
|
||
snyk_logout() { | ||
snyk config clear > /dev/null 2>&1 | ||
} | ||
snyk_login() { | ||
snyk auth "${SMOKE_TESTS_SNYK_TOKEN}" > /dev/null 2>&1 | ||
} | ||
|
||
verify_login_url() { | ||
# https://snyk.io/login?token=uuid-token&utm_medium=cli&utm_source=cli&utm_campaign=cli&os=darwin&docker=false | ||
echo "$1" | grep https | grep -E "^https://(dev\.)?(test\.)?snyk\.io/login\?token=[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\&.*$" | ||
} | ||
snyk_logout() { | ||
snyk config clear > /dev/null 2>&1 | ||
} | ||
|
||
# Consume stdout and checks validates whether it's a valid JSON | ||
check_valid_json() { | ||
printf %s "$1" | jq . > /dev/null | ||
echo $? | ||
} | ||
verify_login_url() { | ||
# https://snyk.io/login?token=uuid-token&utm_medium=cli&utm_source=cli&utm_campaign=cli&os=darwin&docker=false | ||
echo "$1" | grep https | grep -E "^https://(dev\.)?(test\.)?snyk\.io/login\?token=[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\&.*$" | ||
} | ||
|
||
# These 2 commands should run in succession, some CLI functionality uses isCI detection | ||
disable_is_ci_flags() { | ||
# save original value and unset | ||
if [ -n "${CI}" ]; then CI_BACKUP_VALUE=$CI; unset CI; fi | ||
if [ -n "${CIRCLECI}" ]; then CIRCLECI_BACKUP_VALUE=$CIRCLECI; unset CIRCLECI; fi | ||
} | ||
restore_is_ci_flags() { | ||
# recover the original value | ||
if [ -n "${CI}" ]; then CI=$CI_BACKUP_VALUE; unset CI_BACKUP_VALUE; fi | ||
if [ -n "${CIRCLECI}" ]; then CIRCLECI=$CIRCLECI_BACKUP_VALUE; unset CIRCLECI_BACKUP_VALUE; fi | ||
} | ||
# Consume stdout and checks validates whether it's a valid JSON | ||
check_valid_json() { | ||
printf %s "$1" | jq . > /dev/null | ||
echo $? | ||
} | ||
|
||
# These 2 commands should run in succession, some CLI functionality uses isCI detection | ||
disable_is_ci_flags() { | ||
# save original value and unset | ||
if [ -n "${CI}" ]; then CI_BACKUP_VALUE="$CI"; unset CI; fi | ||
if [ -n "${CIRCLECI}" ]; then CIRCLECI_BACKUP_VALUE="$CIRCLECI"; unset CIRCLECI; fi | ||
} | ||
restore_is_ci_flags() { | ||
# recover the original value | ||
if [ -n "${CI}" ]; then CI="$CI_BACKUP_VALUE"; unset CI_BACKUP_VALUE; fi | ||
if [ -n "${CIRCLECI}" ]; then CIRCLECI="$CIRCLECI_BACKUP_VALUE"; unset CIRCLECI_BACKUP_VALUE; fi | ||
} | ||
|
||
check_if_regression_test() { ! [ "${REGRESSION_TEST}" = "1" ]; } | ||
|
||
check_auth_output() { | ||
printf %s "$1" | grep -F -e "To authenticate your account, open the below URL in your browser." -e "Now redirecting you to our auth page, go ahead and log in," > /dev/null | ||
echo $? | ||
} | ||
|
||
echo " | ||
\033[1mS n y k C L I\033[0m | ||
███████╗███╗ ███╗ ██████╗ ██╗ ██╗███████╗ ████████╗███████╗███████╗████████╗███████╗ | ||
██╔════╝████╗ ████║██╔═══██╗██║ ██╔╝██╔════╝ ╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝██╔════╝ | ||
███████╗██╔████╔██║██║ ██║█████╔╝ █████╗ ██║ █████╗ ███████╗ ██║ ███████╗ | ||
╚════██║██║╚██╔╝██║██║ ██║██╔═██╗ ██╔══╝ ██║ ██╔══╝ ╚════██║ ██║ ╚════██║ | ||
███████║██║ ╚═╝ ██║╚██████╔╝██║ ██╗███████╗ ██║ ███████╗███████║ ██║ ███████║ | ||
╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚══════╝ | ||
" | ||
|
||
check_if_regression_test() { ! [ "${REGRESSION_TEST}" = "1" ]; } | ||
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 ./dist/cli\" to test a local build" | ||
echo " " | ||
|
||
check_auth_output() { | ||
printf %s "$1" | grep -F -e "To authenticate your account, open the below URL in your browser." -e "Now redirecting you to our auth page, go ahead and log in," > /dev/null | ||
echo $? | ||
snyk() { | ||
eval "${SNYK_COMMAND:=$ORIGINAL_SNYK_EXECUTABLE}" "$@" | ||
} | ||
} |