Skip to content

Commit

Permalink
test: add diff_scan_summary() test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Jan 20, 2023
1 parent 0b06853 commit 66e783b
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/summary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ link_to_results () {
local push_link="https://github.com/${GITHUB_REPOSITORY}/security/code-scanning?query=tool%3A${SCANNING_TOOL:-"shellcheck"}+branch%3A${GITHUB_REF_NAME:-"main"}+is%3Aopen"
local pull_request_link="https://github.com/${GITHUB_REPOSITORY}/security/code-scanning?query=pr%3A${pull_number}+tool%3A${SCANNING_TOOL:-"shellcheck"}+is%3Aopen"

case ${INPUT_TRIGGERING_EVENT:-${GITHUB_EVENT_NAME}} in
case ${INPUT_TRIGGERING_EVENT-${GITHUB_EVENT_NAME}} in
"push")
echo -e "${push_link}"
;;
Expand Down
87 changes: 87 additions & 0 deletions test/diff_scan_summary.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# SPDX-License-Identifier: GPL-3.0-or-later

setup_file () {
load 'test_helper/common-setup'
_common_setup
}

setup () {
load 'test_helper/bats-assert/load'
load 'test_helper/bats-support/load'
}

@test "diff_scan_summary()" {
source "${PROJECT_ROOT}/src/summary.sh"

export only_changed_scripts=("1.sh" "\$2.sh" "3 .sh")
INPUT_TRIGGERING_EVENT=""

echo -e \
"Error: SHELLCHECK_WARNING:
src/index.sh:53:10: warning[SC2154]: MAIN_HEADING is referenced but not assigned.
Error: SHELLCHECK_WARNING:
src/index.sh:56:14: warning[SC2154]: WHITE is referenced but not assigned.
Error: SHELLCHECK_WARNING:
src/index.sh:56:56: warning[SC2154]: NOCOLOR is referenced but not assigned.
" > ../defects.log

echo -e \
"Error: SHELLCHECK_WARNING:
src/index.sh:7:3: note[SC1091]: Not following: functions.sh: openBinaryFile: does not exist (No such file or directory)
" > ../fixes.log

run diff_scan_summary
assert_success
assert_output \
"Changed scripts: \`3\`
| | ❌ Added | ✅ Fixed |
|:------------------:|:------------------------:|:------------------------:|
| ⚠️ Errors / Warnings / Notes | **3** | **1** |"
}

@test "diff_scan_summary() - no fixes or defects" {
source "${PROJECT_ROOT}/src/summary.sh"

export only_changed_scripts=("1.sh" "\$2.sh" "3 .sh")
INPUT_TRIGGERING_EVENT=""

touch ../defects.log ../fixes.log

run diff_scan_summary
assert_success
assert_output \
"Changed scripts: \`3\`
| | ❌ Added | ✅ Fixed |
|:------------------:|:------------------------:|:------------------------:|
| ⚠️ Errors / Warnings / Notes | **0** | **0** |"
}

@test "diff_scan_summary() - no changed shell scripts" {
source "${PROJECT_ROOT}/src/summary.sh"

export only_changed_scripts=()
INPUT_TRIGGERING_EVENT=""

touch ../defects.log ../fixes.log

run diff_scan_summary
assert_success
assert_output \
"Changed scripts: \`0\`
| | ❌ Added | ✅ Fixed |
|:------------------:|:------------------------:|:------------------------:|
| ⚠️ Errors / Warnings / Notes | **0** | **0** |"
}

teardown () {
rm -f ../defects.log ../fixes.log

export \
only_changed_scripts="" \
INPUT_TRIGGERING_EVENT=""
}

0 comments on commit 66e783b

Please sign in to comment.