File: test_version.sh

package info (click to toggle)
python-semantic-release 10.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 3,112 kB
  • sloc: python: 36,523; sh: 340; makefile: 156
file content (86 lines) | stat: -rw-r--r-- 3,242 bytes parent folder | download | duplicates (2)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash

__file__="$(realpath "${BASH_SOURCE[0]}")"
__directory__="$(dirname "${__file__}")"

if ! [ "${UTILS_LOADED}" = "true" ]; then
    # shellcheck source=tests/utils.sh
    source "$__directory__/../utils.sh"
fi

test_version() {
    # Using default configuration within PSR with no modifications
    # triggering the NOOP mode to prevent errors since the repo doesn't exist
    # We are just trying to test that the root options & tag arguments are
    # passed to the action without a fatal error
    local index="${1:?Index not provided}"
    local test_name="${FUNCNAME[0]}"

    # Create expectations & set env variables that will be passed in for Docker command
    local WITH_VAR_GITHUB_TOKEN="ghp_1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0"
    local WITH_VAR_NO_OPERATION_MODE="true"
    local WITH_VAR_VERBOSITY="2"
    local expected_psr_cmd=".*/bin/semantic-release -vv --noop version"

    # Execute the test & capture output
    # Fatal errors if exit code is not 0
    local output=""
    if ! output="$(run_test "$index. $test_name" 2>&1)"; then
        # Log the output for debugging purposes
        log "$output"
        error "fatal error occurred!"
        error "::error:: $test_name failed!"
        return 1
    fi

    # Evaluate the output to ensure the expected command is present
    if ! printf '%s' "$output" | grep -q -E "$expected_psr_cmd"; then
        # Log the output for debugging purposes
        log "$output"
        error "Failed to find the expected command in the output!"
        error "\tExpected Command: $expected_psr_cmd"
        error "::error:: $test_name failed!"
        return 1
    fi

    log "\n$index. $test_name: PASSED!"
}

test_version_w_custom_config() {
    # Using default configuration within PSR with no modifications
    # triggering the NOOP mode to prevent errors since the repo doesn't exist
    # We are just trying to test that the root options & tag arguments are
    # passed to the action without a fatal error
    local index="${1:?Index not provided}"
    local test_name="${FUNCNAME[0]}"

    # Create expectations & set env variables that will be passed in for Docker command
    local WITH_VAR_GITHUB_TOKEN="ghp_1x2x3x4x5x6x7x8x9x0x1x2x3x4x5x6x7x8x9x0"
    local WITH_VAR_NO_OPERATION_MODE="true"
    local WITH_VAR_VERBOSITY="0"
    local WITH_VAR_CONFIG_FILE="releaserc.toml"
    local expected_psr_cmd=".*/bin/semantic-release --config $WITH_VAR_CONFIG_FILE --noop version"

    # Execute the test & capture output
    # Fatal errors if exit code is not 0
    local output=""
    if ! output="$(run_test "$index. $test_name" 2>&1)"; then
        # Log the output for debugging purposes
        log "$output"
        error "fatal error occurred!"
        error "::error:: $test_name failed!"
        return 1
    fi

    # Evaluate the output to ensure the expected command is present
    if ! printf '%s' "$output" | grep -q "$expected_psr_cmd"; then
        # Log the output for debugging purposes
        log "$output"
        error "Failed to find the expected command in the output!"
        error "\tExpected Command: $expected_psr_cmd"
        error "::error:: $test_name failed!"
        return 1
    fi

    log "\n$index. $test_name: PASSED!"
}