Skip to content

Commit

Permalink
test(insert-icon): ✅ add unit tests and related fixtures
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Villard <[email protected]>
  • Loading branch information
eviweb committed Apr 21, 2022
1 parent cf5092a commit 0a69af1
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/fixtures/COMMIT_EDITMSG
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
docs(thirdpartylibs): add third party libraries file

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vitae
tortor dolor. Vestibulum volutpat dolor sem. Proin ut erat id urna
cursus tristique tincidunt sit amet dolor.

Signed-off-by: Eric Villard <[email protected]>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
#
# Initial commit
#
# Changes to be committed:
# new file: thirdpartylibs.md
#
# Untracked files:
# .gitignore
# bin/
# cog.toml
# install.sh
# koji-gitmoji.toml
# templates/
# tests/
# vendor/
#
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/thirdpartylibs.md b/thirdpartylibs.md
new file mode 100644
index 0000000..d8e8360
--- /dev/null
+++ b/thirdpartylibs.md
@@ -0,0 +1,7 @@
+# Third Party Libraries
+
+* **Bash Ini Parser**: version [0.1.1][bash-ini-parser]
+* **Cocogitto**: version [5.1.0][cocogitto]
+
+[bash-ini-parser]: https://github.com/tadgy/bash-ini-parser
+[cocogitto]: https://github.com/cocogitto/cocogitto/releases/tag/5.1.0
44 changes: 44 additions & 0 deletions tests/fixtures/COMMIT_EDITMSG_WITH_ICON
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
docs(thirdpartylibs): 📚 add third party libraries file

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin vitae
tortor dolor. Vestibulum volutpat dolor sem. Proin ut erat id urna
cursus tristique tincidunt sit amet dolor.

Signed-off-by: Eric Villard <[email protected]>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch main
#
# Initial commit
#
# Changes to be committed:
# new file: thirdpartylibs.md
#
# Untracked files:
# .gitignore
# bin/
# cog.toml
# install.sh
# koji-gitmoji.toml
# templates/
# tests/
# vendor/
#
# ------------------------ >8 ------------------------
# Do not modify or remove the line above.
# Everything below it will be ignored.
diff --git a/thirdpartylibs.md b/thirdpartylibs.md
new file mode 100644
index 0000000..d8e8360
--- /dev/null
+++ b/thirdpartylibs.md
@@ -0,0 +1,7 @@
+# Third Party Libraries
+
+* **Bash Ini Parser**: version [0.1.1][bash-ini-parser]
+* **Cocogitto**: version [5.1.0][cocogitto]
+
+[bash-ini-parser]: https://github.com/tadgy/bash-ini-parser
+[cocogitto]: https://github.com/cocogitto/cocogitto/releases/tag/5.1.0
102 changes: 102 additions & 0 deletions tests/insert-icon-test
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#! /usr/bin/env bash
tests_dir()
{
dirname "$(readlink -f "${BASH_SOURCE}")"
}

lib_dir()
{
echo "$(tests_dir)/lib"
}

fixtures_dir()
{
echo "$(tests_dir)/fixtures"
}

bin_dir()
{
local dir="$(dirname "$(tests_dir)")"

echo "${dir}/bin"
}

. "$(lib_dir)"/functions

declare -A messages_noscope=(
["access: lorem ipsum dolor sit amet"]="access: ♿ lorem ipsum dolor sit amet"
["build: lorem ipsum dolor sit amet"]="build: 📦 lorem ipsum dolor sit amet"
["chore: lorem ipsum dolor sit amet"]="chore: 🧹 lorem ipsum dolor sit amet"
["ci: lorem ipsum dolor sit amet"]="ci: 👷 lorem ipsum dolor sit amet"
["config: lorem ipsum dolor sit amet"]="config: ⚙️ lorem ipsum dolor sit amet"
["deprecate: lorem ipsum dolor sit amet"]="deprecate: ⚠️ lorem ipsum dolor sit amet"
["docs: lorem ipsum dolor sit amet"]="docs: 📚 lorem ipsum dolor sit amet"
["feat: lorem ipsum dolor sit amet"]="feat: ✨ lorem ipsum dolor sit amet"
["fix: lorem ipsum dolor sit amet"]="fix: 🐛 lorem ipsum dolor sit amet"
["init: lorem ipsum dolor sit amet"]="init: 🎉 lorem ipsum dolor sit amet"
["lang: lorem ipsum dolor sit amet"]="lang: 🌐 lorem ipsum dolor sit amet"
["merge: lorem ipsum dolor sit amet"]="merge: 📥 lorem ipsum dolor sit amet"
["metadata: lorem ipsum dolor sit amet"]="metadata: 📇 lorem ipsum dolor sit amet"
["perf: lorem ipsum dolor sit amet"]="perf: ⚡ lorem ipsum dolor sit amet"
["refactor: lorem ipsum dolor sit amet"]="refactor: ♻️ lorem ipsum dolor sit amet"
["release: lorem ipsum dolor sit amet"]="release: 🎁 lorem ipsum dolor sit amet"
["remove: lorem ipsum dolor sit amet"]="remove: 🗑️ lorem ipsum dolor sit amet"
["revert: lorem ipsum dolor sit amet"]="revert: ⏪ lorem ipsum dolor sit amet"
["secfix: lorem ipsum dolor sit amet"]="secfix: 🔒 lorem ipsum dolor sit amet"
["style: lorem ipsum dolor sit amet"]="style: 🎨 lorem ipsum dolor sit amet"
["tag: lorem ipsum dolor sit amet"]="tag: 🔖 lorem ipsum dolor sit amet"
["test: lorem ipsum dolor sit amet"]="test: ✅ lorem ipsum dolor sit amet"
["tool: lorem ipsum dolor sit amet"]="tool: 🔧 lorem ipsum dolor sit amet"
["wip: lorem ipsum dolor sit amet"]="wip: 🚧 lorem ipsum dolor sit amet"
)

declare -A messages_scope=(
["access(scope): lorem ipsum dolor sit amet"]="access(scope): ♿ lorem ipsum dolor sit amet"
["build(scope): lorem ipsum dolor sit amet"]="build(scope): 📦 lorem ipsum dolor sit amet"
["chore(scope): lorem ipsum dolor sit amet"]="chore(scope): 🧹 lorem ipsum dolor sit amet"
["ci(scope): lorem ipsum dolor sit amet"]="ci(scope): 👷 lorem ipsum dolor sit amet"
["config(scope): lorem ipsum dolor sit amet"]="config(scope): ⚙️ lorem ipsum dolor sit amet"
["deprecate(scope): lorem ipsum dolor sit amet"]="deprecate(scope): ⚠️ lorem ipsum dolor sit amet"
["docs(scope): lorem ipsum dolor sit amet"]="docs(scope): 📚 lorem ipsum dolor sit amet"
["feat(scope): lorem ipsum dolor sit amet"]="feat(scope): ✨ lorem ipsum dolor sit amet"
["fix(scope): lorem ipsum dolor sit amet"]="fix(scope): 🐛 lorem ipsum dolor sit amet"
["init(scope): lorem ipsum dolor sit amet"]="init(scope): 🎉 lorem ipsum dolor sit amet"
["lang(scope): lorem ipsum dolor sit amet"]="lang(scope): 🌐 lorem ipsum dolor sit amet"
["merge(scope): lorem ipsum dolor sit amet"]="merge(scope): 📥 lorem ipsum dolor sit amet"
["metadata(scope): lorem ipsum dolor sit amet"]="metadata(scope): 📇 lorem ipsum dolor sit amet"
["perf(scope): lorem ipsum dolor sit amet"]="perf(scope): ⚡ lorem ipsum dolor sit amet"
["refactor(scope): lorem ipsum dolor sit amet"]="refactor(scope): ♻️ lorem ipsum dolor sit amet"
["release(scope): lorem ipsum dolor sit amet"]="release(scope): 🎁 lorem ipsum dolor sit amet"
["remove(scope): lorem ipsum dolor sit amet"]="remove(scope): 🗑️ lorem ipsum dolor sit amet"
["revert(scope): lorem ipsum dolor sit amet"]="revert(scope): ⏪ lorem ipsum dolor sit amet"
["secfix(scope): lorem ipsum dolor sit amet"]="secfix(scope): 🔒 lorem ipsum dolor sit amet"
["style(scope): lorem ipsum dolor sit amet"]="style(scope): 🎨 lorem ipsum dolor sit amet"
["tag(scope): lorem ipsum dolor sit amet"]="tag(scope): 🔖 lorem ipsum dolor sit amet"
["test(scope): lorem ipsum dolor sit amet"]="test(scope): ✅ lorem ipsum dolor sit amet"
["tool(scope): lorem ipsum dolor sit amet"]="tool(scope): 🔧 lorem ipsum dolor sit amet"
["wip(scope): lorem ipsum dolor sit amet"]="wip(scope): 🚧 lorem ipsum dolor sit amet"
)

declare -A messages_amended=(
["chore: 🧹 lorem ipsum dolor sit amet"]="chore: 🧹 lorem ipsum dolor sit amet"
["chore(scope): 🧹 lorem ipsum dolor sit amet"]="chore(scope): 🧹 lorem ipsum dolor sit amet"
)

echo -e "\e[1mInsert Icon Tests\e[21m:"
echo -e "\n> Test messages without scope:"
for message in "${!messages_noscope[@]}"; do
assert_equals "${messages_noscope["${message}"]}" "$("$(bin_dir)"/insert-icon "${message}")"
done

echo -e "\n> Test messages with scope:"
for message in "${!messages_scope[@]}"; do
assert_equals "${messages_scope["${message}"]}" "$("$(bin_dir)"/insert-icon "${message}")"
done

echo -e "\n> Test message with body:"
assert_equals "$(cat "$(fixtures_dir)"/COMMIT_EDITMSG_WITH_ICON)" "$(cat "$(fixtures_dir)"/COMMIT_EDITMSG | "$(bin_dir)"/insert-icon)"

echo -e "\n> Test amended messages:"
for message in "${!messages_amended[@]}"; do
assert_equals "${messages_amended["${message}"]}" "$("$(bin_dir)"/insert-icon "${message}")"
done

0 comments on commit 0a69af1

Please sign in to comment.