Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
atchertchian committed Dec 5, 2024
1 parent 069e382 commit 91e2729
Show file tree
Hide file tree
Showing 6 changed files with 330 additions and 7 deletions.
14 changes: 7 additions & 7 deletions .github/actions/send-teams-notification/compute-message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

COMPUTED_MESSAGE=""

if [ -n "$NEEDS" ]; then
COMPUTED_MESSAGE="$NEEDS\n\n"
fi

if [[ -n "$BLOCK_MESSAGE" && "$APPEND" == 'true' ]] || [ -z "$BLOCK_MESSAGE" ]; then
case $EVENT_NAME in
pull_request)
COMPUTED_MESSAGE="$PR_TITLE"
COMPUTED_MESSAGE="${COMPUTED_MESSAGE}$PR_TITLE"
;;
issues)
COMPUTED_MESSAGE="$ISSUE_BODY"
COMPUTED_MESSAGE="${COMPUTED_MESSAGE}$ISSUE_BODY"
;;
*)
COMPUTED_MESSAGE="$COMMIT_MESSAGE"
COMPUTED_MESSAGE="${COMPUTED_MESSAGE}$COMMIT_MESSAGE"
;;
esac
fi
Expand All @@ -23,10 +27,6 @@ if [ -n "$BLOCK_MESSAGE" ]; then
COMPUTED_MESSAGE="${COMPUTED_MESSAGE}$BLOCK_MESSAGE"
fi

if [ -n "$NEEDS" ]; then
COMPUTED_MESSAGE="${COMPUTED_MESSAGE}\n\n$NEEDS"
fi

if [ -n "$COMPUTED_MESSAGE" ]; then
COMPUTED_MESSAGE="${COMPUTED_MESSAGE}"
COMPUTED_MESSAGE=$(printf "${COMPUTED_MESSAGE}" | sed -z 's/\n/\\n/g' | sed -r 's/"/\\\"/g' | sed -e 's/\r//g')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
AAE-12140 Check and fix inconsistent scenarios in UAT (#734)

* AAE-12140 Add assertion to check for correct application status

Co-authored-by: Elias Ricken de Medeiros <[email protected]>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.\nAenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,\npellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.\n\nIn enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt.\nCras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim.\n\nAliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet.\nEtiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus.\nMaecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel,\nluctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante.\n\nEtiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget\nbibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut,\nmollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus\norci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget,\nimperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris.\nPraesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui.\n\nAenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis\nhendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non,\nauctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada.\n\nPraesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante\nipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac\nplacerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc.\nVestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praes
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor.
Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec,
pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.

In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt.
Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim.

Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet.
Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus.
Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel,
luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante.

Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget
bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut,
mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus
orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget,
imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris.
Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui.

Aenean ut eros et nisl sagittis vestibulum. Nullam nulla eros, ultricies sit amet, nonummy id, imperdiet feugiat, pede. Sed lectus. Donec mollis
hendrerit risus. Phasellus nec sem in justo pellentesque facilisis. Etiam imperdiet imperdiet orci. Nunc nec neque. Phasellus leo dolor, tempus non,
auctor et, hendrerit quis, nisi. Curabitur ligula sapien, tincidunt non, euismod vitae, posuere imperdiet, leo. Maecenas malesuada.

Praesent congue erat at massa. Sed cursus turpis vitae tortor. Donec posuere vulputate arcu. Phasellus accumsan cursus velit. Vestibulum ante
ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Sed aliquam, nisi quis porttitor congue, elit erat euismod orci, ac
placerat dolor lectus quis orci. Phasellus consectetuer vestibulum elit. Aenean tellus metus, bibendum sed, posuere ac, mattis non, nunc.
Vestibulum fringilla pede sit amet augue. In turpis. Pellentesque posuere. Praesent turpis.

Aenean posuere, tortor sed cursus feugi.
10 changes: 10 additions & 0 deletions .github/actions/send-teams-notification/tests/sample-needs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"build": {
"result": "success",
"outputs": {}
},
"promote": {
"result": "failure",
"outputs": {}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,278 @@
setup() {
# Runs everywhere
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
PATH="$DIR/..:$PATH"

# Mock send-teams-notification defaults
export PR_TITLE="fix(jx-updatebot-pr): update release binary version to 0.3.13 #158"
export ISSUE_BODY=$(cat << 'body'
This PR adds support for retrying `jx-updatebot-pr` action in case there is a race condition on the target pr branch due to a concurrent commit from another project, i.e.
```
- uses: Alfresco/alfresco-build-tools/.github/actions/jx-updatebot-pr@ref
with:
retries: '3'
retries-wait: '10'
```
body
)
export COMMIT_MESSAGE=$(cat << 'commit'
fix: update retry inputs to use string type
* use strings
* add tests
commit
)
}

@test "basic teams message" {
export BLOCK_MESSAGE="my custom message"

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result<<EOF
my custom message
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "pull_request teams message" {
export EVENT_NAME=pull_request

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result<<EOF
fix(jx-updatebot-pr): update release binary version to 0.3.13 #158
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "multiline markdown for issues teams message" {
export EVENT_NAME=issues

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << 'BATS'
result<<EOF
This PR adds support for retrying `jx-updatebot-pr` action in case there is a race condition on the target pr branch due to a concurrent commit from another project, i.e.\n\n```\n- uses: Alfresco/alfresco-build-tools/.github/actions/jx-updatebot-pr@ref\n with:\n retries: '3'\n retries-wait: '10'\n\n```
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "multiline commit message for default teams message" {
export EVENT_NAME=whatever

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << 'BATS'
result<<EOF
fix: update retry inputs to use string type\n\n* use strings\n* add tests
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "multiline commit message using CTRL-M" {
export EVENT_NAME=whatever
export COMMIT_MESSAGE=$(<$BATS_TEST_DIRNAME/sample-commit-message.txt)

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << 'BATS'
result<<EOF
AAE-12140 Check and fix inconsistent scenarios in UAT (#734)\n\n* AAE-12140 Add assertion to check for correct application status\n\nCo-authored-by: Elias Ricken de Medeiros <[email protected]>
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "empty teams message" {
export COMMIT_MESSAGE=""

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result=
BATS
)

[ "$output" = "$expected_output" ]
}

@test "empty block message" {
export BLOCK_MESSAGE=""

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result<<EOF
fix: update retry inputs to use string type\n\n* use strings\n* add tests
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "message with double quotes" {
export BLOCK_MESSAGE="Message with \"double quotes\""

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result<<EOF
Message with \"double quotes\"
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "message with single quotes" {
export BLOCK_MESSAGE="Message with 'single quotes'"

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result<<EOF
Message with 'single quotes'
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "empty block message append" {
export EVENT_NAME=push
export BLOCK_MESSAGE=""
export APPEND="true"

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result<<EOF
fix: update retry inputs to use string type\n\n* use strings\n* add tests
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "block message append" {
export EVENT_NAME=push
export BLOCK_MESSAGE="bye"
export APPEND="true"

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result<<EOF
fix: update retry inputs to use string type\n\n* use strings\n* add tests\n\nbye
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "block message append empty default" {
export EVENT_NAME=push
export COMMIT_MESSAGE=""
export BLOCK_MESSAGE="bye"
export APPEND="true"

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result<<EOF
bye
EOF
BATS
)

[ "$output" = "$expected_output" ]
}

@test "long message" {
export COMMIT_MESSAGE=$(<$BATS_TEST_DIRNAME/sample-long-message.txt)
export CUT_MESSAGE=$(<$BATS_TEST_DIRNAME/sample-long-message-cut.txt)

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << BATS
result<<EOF
${CUT_MESSAGE}
EOF
BATS
)

[ "$output" = "$expected_output" ]

}

@test "needs" {
export NEEDS_JSON=$(<$BATS_TEST_DIRNAME/sample-needs.json)
export NEEDS=$(echo $NEEDS_JSON | jq -r 'to_entries[] | "\(.key): \(.value.result)"')

run compute-message.sh

[ "$status" -eq 0 ]

expected_output=$(cat << 'BATS'
result<<EOF
build: success\npromote: failure\n\nfix: update retry inputs to use string type\n\n* use strings\n* add tests
EOF
BATS
)

echo $output
echo $expected_output

[ "$output" = "$expected_output" ]

}

0 comments on commit 91e2729

Please sign in to comment.