|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +__file__="$(realpath "${BASH_SOURCE[0]}")" |
| 4 | +__directory__="$(dirname "${__file__}")" |
| 5 | + |
| 6 | +if ! [ "${UTILS_LOADED}" = "true" ]; then |
| 7 | + # shellcheck source=tests/utils.sh |
| 8 | + source "$__directory__/../utils.sh" |
| 9 | +fi |
| 10 | + |
| 11 | +test_with_custom_config() { |
| 12 | + # Using default configuration within PSR with no modifications |
| 13 | + # triggering the NOOP mode to prevent errors since the repo doesn't exist |
| 14 | + # We are just trying to test that the root options are passed to the action |
| 15 | + # without a fatal error |
| 16 | + local index="${1:?Index not provided}" |
| 17 | + local test_name="${FUNCNAME[0]}" |
| 18 | + |
| 19 | + # Create expectations & set env variables that will be passed in for Docker command |
| 20 | + local WITH_VAR_GITHUB_TOKEN="ghp_1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0" |
| 21 | + local WITH_VAR_NO_OPERATION_MODE="true" |
| 22 | + local WITH_VAR_CONFIG_FILE="releaserc.toml" |
| 23 | + local expected_psr_cmd=".*/bin/semantic-release -v --config releaserc.toml --noop publish" |
| 24 | + |
| 25 | + # Execute the test & capture output |
| 26 | + # Fatal errors if exit code is not 0 |
| 27 | + local output="" |
| 28 | + if ! output="$(run_test "$index. $test_name" 2>&1)"; then |
| 29 | + # Log the output for debugging purposes |
| 30 | + log "$output" |
| 31 | + error "fatal error occurred!" |
| 32 | + error "::error:: $test_name failed!" |
| 33 | + return 1 |
| 34 | + fi |
| 35 | + |
| 36 | + # Evaluate the output to ensure the expected command is present |
| 37 | + if ! printf '%s' "$output" | grep -q "$expected_psr_cmd"; then |
| 38 | + # Log the output for debugging purposes |
| 39 | + log "$output" |
| 40 | + error "Failed to find the expected command in the output!" |
| 41 | + error "\tExpected Command: $expected_psr_cmd" |
| 42 | + error "::error:: $test_name failed!" |
| 43 | + return 1 |
| 44 | + fi |
| 45 | + |
| 46 | + log "\n$index. $test_name: PASSED!" |
| 47 | +} |
0 commit comments