Skip to content

Commit

Permalink
test: add summary() test
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Jan 20, 2023
1 parent 23049a0 commit 2d4eb49
Showing 1 changed file with 312 additions and 0 deletions.
312 changes: 312 additions & 0 deletions test/summary.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,312 @@
# 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 "summary()" {
source "${PROJECT_ROOT}/src/functions.sh"
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 summary
assert_success
assert_output \
"### Differential ShellCheck 🐚
Changed scripts: \`3\`
| | ❌ Added | ✅ Fixed |
|:------------------:|:------------------------:|:------------------------:|
| ⚠️ Errors / Warnings / Notes | **3** | **1** |
#### Useful links
- [Differential ShellCheck Documentation](https://github.com/redhat-plumbers-in-action/differential-shellcheck#readme)
- [ShellCheck Documentation](https://github.com/koalaman/shellcheck#readme)
---
_ℹ️ If you have an issue with this GitHub action, please try to run it in the [debug mode](https://github.blog/changelog/2022-05-24-github-actions-re-run-jobs-with-debug-logging/) and submit an [issue](https://github.com/redhat-plumbers-in-action/differential-shellcheck/issues/new)._"
}

@test "summary() - TRIGGERING_EVENT = push" {
source "${PROJECT_ROOT}/src/functions.sh"
source "${PROJECT_ROOT}/src/summary.sh"

export only_changed_scripts=("1.sh" "\$2.sh" "3 .sh")
INPUT_TRIGGERING_EVENT="push"
GITHUB_REPOSITORY="test-user/test-repo"
GITHUB_REF_NAME="test-branch"
SCANNING_TOOL="not-shellcheck"
GITHUB_REF="refs/heads/${GITHUB_REF_NAME}"

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 summary
assert_success
assert_output \
"### Differential ShellCheck 🐚
Changed scripts: \`3\`
| | ❌ Added | ✅ Fixed |
|:------------------:|:------------------------:|:------------------------:|
| ⚠️ [Errors / Warnings / Notes](https://github.com/${GITHUB_REPOSITORY}/security/code-scanning?query=tool%3A${SCANNING_TOOL}+branch%3A${GITHUB_REF_NAME}+is%3Aopen) | **3** | **1** |
#### Useful links
- [Differential ShellCheck Documentation](https://github.com/redhat-plumbers-in-action/differential-shellcheck#readme)
- [ShellCheck Documentation](https://github.com/koalaman/shellcheck#readme)
---
_ℹ️ If you have an issue with this GitHub action, please try to run it in the [debug mode](https://github.blog/changelog/2022-05-24-github-actions-re-run-jobs-with-debug-logging/) and submit an [issue](https://github.com/redhat-plumbers-in-action/differential-shellcheck/issues/new)._"
}

@test "summary() - TRIGGERING_EVENT = pull_request" {
source "${PROJECT_ROOT}/src/functions.sh"
source "${PROJECT_ROOT}/src/summary.sh"

export only_changed_scripts=("1.sh" "\$2.sh" "3 .sh")
INPUT_TRIGGERING_EVENT="pull_request"
GITHUB_REPOSITORY="test-user/test-repo"
PR_NUMBER=123
SCANNING_TOOL="not-shellcheck"
GITHUB_REF="refs/pull/${PR_NUMBER}/merge"

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 summary
assert_success
assert_output \
"### Differential ShellCheck 🐚
Changed scripts: \`3\`
| | ❌ Added | ✅ Fixed |
|:------------------:|:------------------------:|:------------------------:|
| ⚠️ [Errors / Warnings / Notes](https://github.com/${GITHUB_REPOSITORY}/security/code-scanning?query=pr%3A${PR_NUMBER}+tool%3A${SCANNING_TOOL}+is%3Aopen) | **3** | **1** |
#### Useful links
- [Differential ShellCheck Documentation](https://github.com/redhat-plumbers-in-action/differential-shellcheck#readme)
- [ShellCheck Documentation](https://github.com/koalaman/shellcheck#readme)
---
_ℹ️ If you have an issue with this GitHub action, please try to run it in the [debug mode](https://github.blog/changelog/2022-05-24-github-actions-re-run-jobs-with-debug-logging/) and submit an [issue](https://github.com/redhat-plumbers-in-action/differential-shellcheck/issues/new)._"
}

@test "summary() - no fixes or defects" {
source "${PROJECT_ROOT}/src/functions.sh"
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 summary
assert_success
assert_output \
"### Differential ShellCheck 🐚
Changed scripts: \`3\`
| | ❌ Added | ✅ Fixed |
|:------------------:|:------------------------:|:------------------------:|
| ⚠️ Errors / Warnings / Notes | **0** | **0** |
#### Useful links
- [Differential ShellCheck Documentation](https://github.com/redhat-plumbers-in-action/differential-shellcheck#readme)
- [ShellCheck Documentation](https://github.com/koalaman/shellcheck#readme)
---
_ℹ️ If you have an issue with this GitHub action, please try to run it in the [debug mode](https://github.blog/changelog/2022-05-24-github-actions-re-run-jobs-with-debug-logging/) and submit an [issue](https://github.com/redhat-plumbers-in-action/differential-shellcheck/issues/new)._"
}

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

export only_changed_scripts=()
INPUT_TRIGGERING_EVENT=""

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

run summary
assert_success
assert_output \
"### Differential ShellCheck 🐚
Changed scripts: \`0\`
| | ❌ Added | ✅ Fixed |
|:------------------:|:------------------------:|:------------------------:|
| ⚠️ Errors / Warnings / Notes | **0** | **0** |
#### Useful links
- [Differential ShellCheck Documentation](https://github.com/redhat-plumbers-in-action/differential-shellcheck#readme)
- [ShellCheck Documentation](https://github.com/koalaman/shellcheck#readme)
---
_ℹ️ If you have an issue with this GitHub action, please try to run it in the [debug mode](https://github.blog/changelog/2022-05-24-github-actions-re-run-jobs-with-debug-logging/) and submit an [issue](https://github.com/redhat-plumbers-in-action/differential-shellcheck/issues/new)._"
}

@test "summary() - FULL_SCAN = true" {
source "${PROJECT_ROOT}/src/functions.sh"
source "${PROJECT_ROOT}/src/summary.sh"

export all_scripts=("1.sh" "\$2.sh" "3 .sh")
INPUT_TRIGGERING_EVENT=""
FULL_SCAN=0

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 summary
assert_success
assert_output \
"### Differential ShellCheck 🐚
Changed scripts: \`0\`
| | ❌ Added | ✅ Fixed |
|:------------------:|:------------------------:|:------------------------:|
| ⚠️ Errors / Warnings / Notes | **3** | **1** |
#### Useful links
- [Differential ShellCheck Documentation](https://github.com/redhat-plumbers-in-action/differential-shellcheck#readme)
- [ShellCheck Documentation](https://github.com/koalaman/shellcheck#readme)
---
_ℹ️ If you have an issue with this GitHub action, please try to run it in the [debug mode](https://github.blog/changelog/2022-05-24-github-actions-re-run-jobs-with-debug-logging/) and submit an [issue](https://github.com/redhat-plumbers-in-action/differential-shellcheck/issues/new)._"
}

@test "summary() - FULL_SCAN = true && is_strict_check_on_push_demanded = true" {
source "${PROJECT_ROOT}/src/functions.sh"
source "${PROJECT_ROOT}/src/summary.sh"

export all_scripts=("1.sh" "\$2.sh" "3 .sh")
INPUT_TRIGGERING_EVENT="push"
GITHUB_REPOSITORY="test-user/test-repo"
GITHUB_REF_NAME="test-branch"
SCANNING_TOOL="not-shellcheck"
GITHUB_REF="refs/heads/${GITHUB_REF_NAME}"
FULL_SCAN=0
INPUT_STRICT_CHECK_ON_PUSH="true"

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 summary
assert_success
assert_output \
"### Differential ShellCheck 🐚
Number of scripts: \`3\`
[Defects](https://github.com/${GITHUB_REPOSITORY}/security/code-scanning?query=tool%3A${SCANNING_TOOL}+branch%3A${GITHUB_REF_NAME}+is%3Aopen): **3**
#### Useful links
- [Differential ShellCheck Documentation](https://github.com/redhat-plumbers-in-action/differential-shellcheck#readme)
- [ShellCheck Documentation](https://github.com/koalaman/shellcheck#readme)
---
_ℹ️ If you have an issue with this GitHub action, please try to run it in the [debug mode](https://github.blog/changelog/2022-05-24-github-actions-re-run-jobs-with-debug-logging/) and submit an [issue](https://github.com/redhat-plumbers-in-action/differential-shellcheck/issues/new)._"
}

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

export \
only_changed_scripts="" \
INPUT_TRIGGERING_EVENT="" \
GITHUB_REPOSITORY="" \
GITHUB_REF_NAME="" \
SCANNING_TOOL="" \
GITHUB_REF="" \
PR_NUMBER="" \
FULL_SCAN="" \
INPUT_STRICT_CHECK_ON_PUSH=""
}

0 comments on commit 2d4eb49

Please sign in to comment.