|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | +# contributor license agreements. See the NOTICE file distributed with |
| 4 | +# this work for additional information regarding copyright ownership. |
| 5 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | +# (the "License"); you may not use this file except in compliance with |
| 7 | +# the License. You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +load functions_test_helper |
| 18 | + |
| 19 | +setup_gha() { |
| 20 | + # Source the githubactions robot |
| 21 | + # shellcheck disable=SC1090 |
| 22 | + . "${BATS_TEST_DIRNAME}/../../main/shell/robots.d/githubactions.sh" |
| 23 | + |
| 24 | + # Mock required functions |
| 25 | + big_console_header() { :; } |
| 26 | + clock_display() { echo "$1s"; } |
| 27 | + get_artifact_url() { echo ""; } |
| 28 | + yetus_error() { echo "$*" >&2; } |
| 29 | + SED="sed" |
| 30 | + |
| 31 | + # Set up step summary file |
| 32 | + GITHUB_STEP_SUMMARY="${TMP}/step_summary.md" |
| 33 | + touch "${GITHUB_STEP_SUMMARY}" |
| 34 | + export GITHUB_STEP_SUMMARY |
| 35 | + |
| 36 | + # Initialize arrays and settings |
| 37 | + TP_VOTE_TABLE=() |
| 38 | + TP_TEST_TABLE=() |
| 39 | + TP_HEADER=() |
| 40 | + TP_FOOTER_TABLE=() |
| 41 | + VERSION="0.0.0-test" |
| 42 | + GITHUB_USE_EMOJI_VOTE=false |
| 43 | +} |
| 44 | + |
| 45 | +@test "githubactions_finalreport (no GITHUB_STEP_SUMMARY)" { |
| 46 | + setup_gha |
| 47 | + unset GITHUB_STEP_SUMMARY |
| 48 | + run githubactions_finalreport |
| 49 | + [ "${status}" -eq 0 ] |
| 50 | +} |
| 51 | + |
| 52 | +@test "githubactions_finalreport (GITHUB_STEP_SUMMARY not writable)" { |
| 53 | + setup_gha |
| 54 | + GITHUB_STEP_SUMMARY="/nonexistent/path/summary.md" |
| 55 | + run githubactions_finalreport |
| 56 | + [ "${status}" -eq 0 ] |
| 57 | +} |
| 58 | + |
| 59 | +@test "githubactions_finalreport (success result)" { |
| 60 | + setup_gha |
| 61 | + RESULT=0 |
| 62 | + TP_VOTE_TABLE=("|+1| compile |60||passed|") |
| 63 | + run githubactions_finalreport |
| 64 | + [ "${status}" -eq 0 ] |
| 65 | + grep -q ":confetti_ball:" "${GITHUB_STEP_SUMMARY}" |
| 66 | + grep -q "+1 overall" "${GITHUB_STEP_SUMMARY}" |
| 67 | + grep -q "compile" "${GITHUB_STEP_SUMMARY}" |
| 68 | +} |
| 69 | + |
| 70 | +@test "githubactions_finalreport (failure result)" { |
| 71 | + setup_gha |
| 72 | + RESULT=1 |
| 73 | + TP_VOTE_TABLE=("|-1| unit |120||tests failed|") |
| 74 | + run githubactions_finalreport |
| 75 | + [ "${status}" -eq 0 ] |
| 76 | + grep -q ":broken_heart:" "${GITHUB_STEP_SUMMARY}" |
| 77 | + grep -q -- "-1 overall" "${GITHUB_STEP_SUMMARY}" |
| 78 | + grep -q "unit" "${GITHUB_STEP_SUMMARY}" |
| 79 | +} |
| 80 | + |
| 81 | +@test "githubactions_finalreport (with headers)" { |
| 82 | + setup_gha |
| 83 | + RESULT=0 |
| 84 | + TP_HEADER=("Build completed successfully") |
| 85 | + TP_VOTE_TABLE=("|+1| compile |60||passed|") |
| 86 | + run githubactions_finalreport |
| 87 | + [ "${status}" -eq 0 ] |
| 88 | + grep -q "Build completed successfully" "${GITHUB_STEP_SUMMARY}" |
| 89 | +} |
| 90 | + |
| 91 | +@test "githubactions_finalreport (with failed tests)" { |
| 92 | + setup_gha |
| 93 | + RESULT=1 |
| 94 | + TP_VOTE_TABLE=("|-1| unit |120||tests failed|") |
| 95 | + TP_TEST_TABLE=("| Failed tests | org.example.TestFoo |") |
| 96 | + run githubactions_finalreport |
| 97 | + [ "${status}" -eq 0 ] |
| 98 | + grep -q "Failed Tests" "${GITHUB_STEP_SUMMARY}" |
| 99 | + grep -q "TestFoo" "${GITHUB_STEP_SUMMARY}" |
| 100 | +} |
| 101 | + |
| 102 | +@test "githubactions_finalreport (vote table header row)" { |
| 103 | + setup_gha |
| 104 | + RESULT=0 |
| 105 | + TP_VOTE_TABLE=("|H||||Prechecks|") |
| 106 | + run githubactions_finalreport |
| 107 | + [ "${status}" -eq 0 ] |
| 108 | + grep -q "_Prechecks_" "${GITHUB_STEP_SUMMARY}" |
| 109 | +} |
| 110 | + |
| 111 | +@test "githubactions_finalreport (emoji vote enabled)" { |
| 112 | + setup_gha |
| 113 | + RESULT=0 |
| 114 | + GITHUB_USE_EMOJI_VOTE=true |
| 115 | + TP_VOTE_TABLE=("|+1| compile |60||passed|") |
| 116 | + run githubactions_finalreport |
| 117 | + [ "${status}" -eq 0 ] |
| 118 | + grep -q ":green_heart:" "${GITHUB_STEP_SUMMARY}" |
| 119 | +} |
| 120 | + |
| 121 | +@test "githubactions_finalreport (emoji vote disabled)" { |
| 122 | + setup_gha |
| 123 | + RESULT=0 |
| 124 | + GITHUB_USE_EMOJI_VOTE=false |
| 125 | + TP_VOTE_TABLE=("|+1| compile |60||passed|") |
| 126 | + run githubactions_finalreport |
| 127 | + [ "${status}" -eq 0 ] |
| 128 | + # Should have +1 but not the emoji |
| 129 | + grep -q "+1" "${GITHUB_STEP_SUMMARY}" |
| 130 | + ! grep -q ":green_heart:" "${GITHUB_STEP_SUMMARY}" |
| 131 | +} |
| 132 | + |
| 133 | +setup_docker_support() { |
| 134 | + # Source the githubactions robot |
| 135 | + # shellcheck disable=SC1090 |
| 136 | + . "${BATS_TEST_DIRNAME}/../../main/shell/robots.d/githubactions.sh" |
| 137 | + |
| 138 | + # Mock add_docker_env |
| 139 | + DOCKER_EXTRAENVS=() |
| 140 | + add_docker_env() { |
| 141 | + for k in "$@"; do |
| 142 | + DOCKER_EXTRAENVS+=("${k}") |
| 143 | + done |
| 144 | + } |
| 145 | + |
| 146 | + DOCKER_EXTRAARGS=() |
| 147 | + DOCKER_WORK_DIR="/workdir" |
| 148 | +} |
| 149 | + |
| 150 | +@test "githubactions_docker_support (no GITHUB_STEP_SUMMARY)" { |
| 151 | + setup_docker_support |
| 152 | + unset GITHUB_STEP_SUMMARY |
| 153 | + run githubactions_docker_support |
| 154 | + [ "${status}" -eq 0 ] |
| 155 | + [ "${#DOCKER_EXTRAARGS[@]}" -eq 0 ] |
| 156 | +} |
| 157 | + |
| 158 | +@test "githubactions_docker_support (GITHUB_STEP_SUMMARY file missing)" { |
| 159 | + setup_docker_support |
| 160 | + GITHUB_STEP_SUMMARY="/nonexistent/path/summary.md" |
| 161 | + run githubactions_docker_support |
| 162 | + [ "${status}" -eq 0 ] |
| 163 | + [ "${#DOCKER_EXTRAARGS[@]}" -eq 0 ] |
| 164 | +} |
| 165 | + |
| 166 | +@test "githubactions_docker_support (mounts summary file)" { |
| 167 | + setup_docker_support |
| 168 | + GITHUB_STEP_SUMMARY="${TMP}/step_summary.md" |
| 169 | + touch "${GITHUB_STEP_SUMMARY}" |
| 170 | + githubactions_docker_support |
| 171 | + [[ "${DOCKER_EXTRAARGS[*]}" == *"-v"* ]] |
| 172 | + [[ "${DOCKER_EXTRAARGS[*]}" == *"${TMP}/step_summary.md:/workdir/step_summary.md"* ]] |
| 173 | + [ "${GITHUB_STEP_SUMMARY}" = "/workdir/step_summary.md" ] |
| 174 | + [[ "${DOCKER_EXTRAENVS[*]}" == *"GITHUB_STEP_SUMMARY"* ]] |
| 175 | +} |
0 commit comments