-
Notifications
You must be signed in to change notification settings - Fork 532
/
spec_helper.sh
37 lines (31 loc) · 1.06 KB
/
spec_helper.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#shellcheck shell=sh
set -e
print_snyk_config() {
snyk config
}
snyk_login() {
snyk auth "${SMOKE_TESTS_SNYK_TOKEN}"
}
snyk_logout() {
snyk config clear
}
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}\&.*$"
}
# 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
}