Skip to content

Commit

Permalink
Add enforce insert issue number unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Anarcroth committed Oct 14, 2019
1 parent a6bf07c commit 2626783
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions tests/enforce-insert-issue-number-test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bats

LOG="./tests/tests.log"
TEST_BRANCH="issue-9999999999/add-this-and-that"

logTest() {
# $1 indicates the test status [PASS, FAIL]
date >> "$LOG"
echo "enforce insert issue number test: $1" >> "$LOG"
echo "" >> "$LOG"
echo "--------------------------------------------" >> "$LOG"
echo "" >> "$LOG"
}

setup() {
# Create a test branch that will be used to verify that the `commit-msg` hook works
# 'issue-9999999999' is highly unlikely to exists and thus safer than having a normal issue number
# which might collide with a real branch.
git checkout -b "$TEST_BRANCH"
}

teardown() {
# Go back to the previous branch
git checkout -
# Remove test branch
git branch -D "$TEST_BRANCH"
}

@test "correct issue number format" {
run $(git commit --allow-empty -m "$TEST_BRANCH")
if [ "$status" -eq 0 ]; then
logTest "PASS"
else
logTest "FAIL"
[ "$output" = "incorrect commit message specified" ]
fi
}

@test "wrong issue number format" {
run git commit --allow-empty -m "NOT-CORRECT-ISSUE-FORMAT"
if [ "$status" -eq 1 ]; then
logTest "PASS"
else
logTest "FAIL"
[ "$output" = "incorrect commit message specified" ]
fi
}

0 comments on commit 2626783

Please sign in to comment.