forked from Josee9988/Josee9988
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from Josee9988/feature/unit-testing
Feature/unit testing
- Loading branch information
Showing
8 changed files
with
1,585 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,8 @@ The project's team and community take security issues. | |
|
||
We appreciate your efforts to responsibly disclose your findings and will make every effort to acknowledge your contributions. | ||
|
||
To report a security issue, go to the project's issues and create a new issue using the ⚠️ Security Report``issue template. | ||
To report a security issue, go to the project's issues and create a new issue using the ⚠️ Security Report 'issue template'. | ||
|
||
Read carefully the instructions of this issue template, and if your report could leak data or might expose | ||
how to gain access to a restricted area or break the system, | ||
please email [[email protected]](mailto:[email protected]) and include the word "SECURITY" in the subject line. | ||
Read carefully the instructions of this issue template, and if your report could leak data or might expose how to gain access to a restricted area or break the system, please email [[email protected]](mailto:[email protected]) and include the word "SECURITY" in the subject line. | ||
|
||
We'll endeavour to respond quickly, and will keep you updated throughout the process. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ NC='\033[0m' # No Color | |
UPurple='\033[4;35m' | ||
BBLUE='\033[1;34m' | ||
GREEN='\033[1;32m' | ||
OMIT_STR="--omit-commit-and-confirmation" | ||
FILE_FUNCTION_HELPERS=bin/FUNCTION_HELPERS.sh | ||
|
||
if [ ! -f "$FILE_FUNCTION_HELPERS" ]; then # check if the function helpers file is not found | ||
|
@@ -61,34 +62,49 @@ else | |
NEW_EMAIL=$3 | ||
fi | ||
|
||
###### START OF THE SCRIPT ###### | ||
echo -e "Thanks for using ${GREEN}Josee9988/project-template${NC}" | ||
echo -e "Read carefully all the documentation before you continue executing this script: ${UPurple}https://github.com/Josee9988/project-template${NC}\n" | ||
# prompt for the, mail and type of the project | ||
read -p "Enter $(echo -e "$BBLUE""what your project is""$NC") (program/extension/API/web/CLI tool/backend/frontend/scrapper/automation tool/etc): " PROJECT_TYPE | ||
|
||
if [ -n "$4" ]; then # if the project's type has been manually specified | ||
PROJECT_TYPE=$4 | ||
else | ||
read -p "Enter $(echo -e "$BBLUE""what your project is""$NC") (program/extension/API/web/CLI tool/backend/frontend/scrapper/automation tool/etc): " PROJECT_TYPE | ||
fi | ||
|
||
if [ "$5" = "$OMIT_STR" ]; then # if the ignore flag has been manually specified | ||
choice="y" | ||
else | ||
read -p "Is this data correct: username \"$(echo -e "$GREEN""$NEW_USERNAME""$NC")\", email: \"$(echo -e "$GREEN""$NEW_EMAIL""$NC")\", project name: \"$(echo -e "$GREEN""$PROJECT_NAME""$NC")\", of type: \"$(echo -e "$GREEN""$PROJECT_TYPE""$NC")\" (y/n)? " choice | ||
fi | ||
|
||
###### START OF THE SCRIPT ###### | ||
|
||
# confirm that the data is correct | ||
read -p "Is this data correct: username \"$(echo -e "$GREEN""$NEW_USERNAME""$NC")\", email: \"$(echo -e "$GREEN""$NEW_EMAIL""$NC")\", project name: \"$(echo -e "$GREEN""$PROJECT_NAME""$NC")\", of type: \"$(echo -e "$GREEN""$PROJECT_TYPE""$NC")\" (y/n)? " choice | ||
case "$choice" in | ||
y | Y) | ||
center "Setting everything up for you ;)" | ||
|
||
# replace the username and email | ||
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/Josee9988/${NEW_USERNAME}/g" | ||
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/[email protected]/${NEW_EMAIL}/g" | ||
find .github/ -type f -name "*" -print0 | xargs -0 sed -i "s/project-template/${PROJECT_NAME}/g" | ||
find .gitignore -type f -name "*" -print0 | xargs -0 sed -i "s/Josee9988\/project-template/${NEW_USERNAME}\/${PROJECT_NAME}/g" | ||
|
||
rm LICENSE # remove the license | ||
rm -r bin/ # remove the bin folder | ||
rm -r tests/ 2>/dev/null || : # remove the tests folder | ||
writeREADME # write the new README.md | ||
writeCHANGELOG # write the basic structure of the CHANGELOG.md | ||
echo -e "# add your own funding links" >.github/FUNDING.yml # remove author's custom funding links | ||
|
||
git add CHANGELOG.md README.md .gitignore .github SETUP_TEMPLATE.sh LICENSE bin # commit the new files | ||
git -c color.status=always status | less -REX # show git status with colours | ||
echo -e "Committing the changes for you :)\n" | ||
git commit -m "Set up '@Josee9988/project-template' template: Personalized files by executing the SETUP_TEMPLATE.sh script.🚀" | ||
echo -e "\nRemember to review every file and customize it as you like.\nYou are ready to start your brand new awesome project🚀🚀." | ||
if [ ! "$5" = "$OMIT_STR" ]; then # if the ignore option for tests has been specified | ||
git add CHANGELOG.md README.md .gitignore .github SETUP_TEMPLATE.sh LICENSE bin # commit the new files | ||
git -c color.status=always status | less -REX # show git status with colours | ||
echo -e "Committing the changes for you :)\n" | ||
git commit -m "Set up '@Josee9988/project-template' template: Personalized files by executing the SETUP_TEMPLATE.sh script.🚀" | ||
echo -e "\nRemember to review every file and customize it as you like.\nYou are ready to start your brand new awesome project🚀🚀." else | ||
fi | ||
|
||
# self remove this script | ||
rm -- "$0" | ||
;; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash | ||
|
||
LGREEN='\033[0;32m' | ||
NC='\033[0m' # No Color | ||
TESTS_TRASH_DIR="tests/.ignore.tests_trash/" | ||
declare -a files=("tests/project_scaffolding_test.sh" "tests/custom_data_test.sh") # all the tests | ||
|
||
center() { | ||
term_width="$(tput cols)" | ||
padding="$(printf '%0.1s' +{1..500})" | ||
echo -e "\n${LGREEN}$(printf '%*.*s %s %*.*s\n' 0 "$(((term_width - 2 - ${#1}) / 2))" "$padding" "$1" 0 "$(((term_width - 1 - ${#1}) / 2))" "$padding")${NC}" | ||
} | ||
|
||
for file in "${files[@]}"; do | ||
mkdir -p tests/.ignore.tests_trash | ||
center "TEST: running test ./$file" | ||
./"$file" | ||
rm -r $TESTS_TRASH_DIR | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#! /bin/bash | ||
# file: examples/custom_data_test.sh | ||
|
||
TESTS_TRASH_DIR="tests/.ignore.tests_trash" | ||
USERNAME="FAKE_USERNAME_TESTS" | ||
NAME="FAKE_NAME_TESTS" | ||
MAIL="FAKE_EMAIL_TESTS" | ||
TYPE="FAKE_TYPE_TESTS" | ||
OMIT_STR="--omit-commit-and-confirmation" | ||
|
||
oneTimeSetUp() { | ||
cp -r * $TESTS_TRASH_DIR --copy-content 2>/dev/null || : | ||
cp -r .github/ $TESTS_TRASH_DIR --copy-contents | ||
cp -r bin/ $TESTS_TRASH_DIR --copy-contents | ||
cp .gitignore $TESTS_TRASH_DIR --copy-contents | ||
rm -r $TESTS_TRASH_DIR/tests/ 2>/dev/null || : | ||
rm -r $TESTS_TRASH_DIR/.git/ 2>/dev/null || : | ||
cd $TESTS_TRASH_DIR || exit | ||
bash SETUP_TEMPLATE.sh $USERNAME $NAME $MAIL $TYPE $OMIT_STR >/dev/null | ||
} | ||
|
||
oneTimeTearDown() { | ||
cd "../.." || exit | ||
} | ||
|
||
# TESTS | ||
suite() { | ||
suite_addTest testDotGithubISSUE_TEMPLATEAsignees | ||
suite_addTest testDotGithubISSUE_TEMPLATEConfig | ||
suite_addTest testDotGithubConfig | ||
suite_addTest testDotGithubSecurity | ||
suite_addTest testDotGithubCODEOWNERS | ||
suite_addTest testDotGitignore | ||
suite_addTest testChangelog | ||
} | ||
|
||
testDotGithubISSUE_TEMPLATEAsignees() { | ||
assigneesWithName="assignees: $USERNAME" | ||
declare -a files=( | ||
".github/ISSUE_TEMPLATE/1-bug-report.md" ".github/ISSUE_TEMPLATE/2-failing-test.md" | ||
".github/ISSUE_TEMPLATE/3-docs-bug.md" ".github/ISSUE_TEMPLATE/4-feature-request.md" | ||
".github/ISSUE_TEMPLATE/5-enhancement-request.md" ".github/ISSUE_TEMPLATE/6-security-report.md" | ||
".github/ISSUE_TEMPLATE/7-question-support.md") | ||
|
||
for file in "${files[@]}"; do | ||
assertTrue " assignee was not found for file $file" "grep -q \"$assigneesWithName\" \"$file\"" | ||
done | ||
} | ||
testDotGithubISSUE_TEMPLATEConfig() { | ||
mailInConfig="url: mailto:$MAIL" | ||
assertTrue "The mail $MAIL was not found in .github/ISSUE_TEMPLATE/config.yml" "grep -q \"$mailInConfig\" \".github/ISSUE_TEMPLATE/config.yml\"" | ||
} | ||
|
||
testDotGithubConfig() { | ||
newIssueWelcomeComment="Thanks for opening your first issue in $USERNAME/$NAME! Be sure to" | ||
assertTrue "The $USERNAME/$NAME was not found in " "grep -q \"$newIssueWelcomeComment\" \".github/config.yml\"" | ||
} | ||
|
||
testDotGithubSecurity() { | ||
securityData1="(mailto:$MAIL)" | ||
securityData2="[$MAIL]" | ||
securityData3="he project's team and community take security issues" | ||
assertTrue "The mail $MAIL was not found in .github/SECURITY.md" "grep -q \"$securityData1\" \".github/SECURITY.md\" && grep -q \"$securityData2\" \".github/SECURITY.md\" && grep -q \"$securityData3\" \".github/SECURITY.md\"" | ||
} | ||
|
||
testDotGithubCODEOWNERS() { | ||
usernameData="$USERNAME" | ||
assertTrue "Could not find the username $USERNAME in the file .github/CODEOWNERS" "grep -q \"$usernameData\" \".github/CODEOWNERS\"" | ||
} | ||
|
||
testDotGitignore() { | ||
gitignoreData1="###> $USERNAME/$NAME ###" | ||
gitignoreData2="###< $USERNAME/$NAME ###" | ||
|
||
assertTrue "Could not find the username $USERNAME and the name $NAME in the .gitignore file" "grep -q \"$gitignoreData1\" \".gitignore\" && grep -q \"$gitignoreData2\" \".gitignore\"" | ||
} | ||
|
||
testChangelog() { | ||
changelogData1="All notable changes to the" | ||
changelogData2="**$NAME**" | ||
changelogData3="$TYPE will be documented in this file." | ||
|
||
assertTrue "Could not find the name $NAME or the type $TYPE in the CHANGELOG.md file" "grep -q \"$changelogData1\" \"CHANGELOG.md\" && grep -q \"$changelogData2\" \"CHANGELOG.md\" && grep -q \"$changelogData3\" \"CHANGELOG.md\"" | ||
} | ||
|
||
# Load and run shUnit2. | ||
. tests/shunit2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#! /bin/bash | ||
# file: examples/project_scaffolding_test.sh | ||
|
||
TESTS_TRASH_DIR="tests/.ignore.tests_trash" | ||
USERNAME="FAKE_USERNAME_TESTS" | ||
NAME="FAKE_NAME_TESTS" | ||
MAIL="FAKE_EMAIL_TESTS" | ||
TYPE="FAKE_TYPE_TESTS" | ||
OMIT_STR="--omit-commit-and-confirmation" | ||
|
||
oneTimeSetUp() { | ||
cp -r * $TESTS_TRASH_DIR --copy-content 2>/dev/null || : | ||
cp -r .github/ $TESTS_TRASH_DIR --copy-contents | ||
cp -r bin/ $TESTS_TRASH_DIR --copy-contents | ||
cp .gitignore $TESTS_TRASH_DIR --copy-contents | ||
rm -r $TESTS_TRASH_DIR/tests/ 2>/dev/null || : | ||
rm -r $TESTS_TRASH_DIR/.git/ 2>/dev/null || : | ||
cd $TESTS_TRASH_DIR || exit | ||
bash SETUP_TEMPLATE.sh $USERNAME $NAME $MAIL $TYPE $OMIT_STR >/dev/null | ||
} | ||
|
||
oneTimeTearDown() { | ||
cd "../.." || exit | ||
} | ||
|
||
# TESTS | ||
suite() { | ||
suite_addTest testDotGithubFolder | ||
suite_addTest testDotGithubISSUE_TEMPLATE | ||
suite_addTest testDotGithubISSUE_TEMPLATEFiles | ||
suite_addTest testDotGithubFiles | ||
suite_addTest testTestRemovedFiles | ||
suite_addTest testGlobalFiles | ||
suite_addTest testRemovedFiles | ||
} | ||
|
||
testDotGithubFolder() { | ||
if [ ! -e ".github/" ]; then | ||
assertEquals ".github file does not exist" 1 0 # error | ||
fi | ||
} | ||
|
||
testDotGithubISSUE_TEMPLATE() { | ||
if [ ! -e ".github/ISSUE_TEMPLATE" ]; then | ||
assertEquals ".github/ISSUE_TEMPLATE was not found" 1 0 # error | ||
fi | ||
} | ||
|
||
testDotGithubISSUE_TEMPLATEFiles() { | ||
declare -a files=( | ||
".github/ISSUE_TEMPLATE/1-bug-report.md" ".github/ISSUE_TEMPLATE/2-failing-test.md" | ||
".github/ISSUE_TEMPLATE/3-docs-bug.md" ".github/ISSUE_TEMPLATE/4-feature-request.md" | ||
".github/ISSUE_TEMPLATE/5-enhancement-request.md" ".github/ISSUE_TEMPLATE/6-security-report.md" | ||
".github/ISSUE_TEMPLATE/7-question-support.md") | ||
|
||
for file in "${files[@]}"; do | ||
assertTrue " $file does not exist" "[ -e \"$file\" ]" | ||
done | ||
} | ||
|
||
testDotGithubFiles() { | ||
declare -a files=( | ||
".github/CODEOWNERS" ".github/CODE_OF_CONDUCT.md" ".github/CONTRIBUTING.md" ".github/ISSUE_TEMPLATE.md" | ||
".github/pull_request_template.md" ".github/SECURITY.md" ".github/SUPPORT.md" ".github/issue_label_bot.yaml" | ||
".github/config.yml" ".github/FUNDING.yml" ".github/settings.yml") | ||
|
||
for file in "${files[@]}"; do | ||
assertTrue " $file does not exist" "[ -e \"$file\" ]" | ||
done | ||
} | ||
|
||
testTestRemovedFiles() { | ||
filesFound=0 | ||
if [ -e "tests/" ] && [ -e "tests/shunit2" ] && [ -e "tests/TESTS_RUNNER.sh" ]; then | ||
filesFound=1 | ||
fi | ||
assertNotEquals " tests folder of some files were found" 1 $filesFound | ||
} | ||
|
||
testGlobalFiles() { | ||
filesFound=0 | ||
if [ -e ".gitignore" ] && [ -e "CHANGELOG.md" ] && [ -e "README.md" ]; then | ||
filesFound=1 | ||
fi | ||
assertEquals " gitignore, changelog or readme were not found" 1 $filesFound | ||
} | ||
|
||
testRemovedFiles() { | ||
filesFound=0 | ||
if [ -e "LICENSE" ] && [ -e "bin" ] && [ -e "bin/FUNCTION_HELPERS.sh" ]; then | ||
filesFound=1 | ||
fi | ||
assertNotEquals " LICENSE or the bin directory were found" 1 $filesFound | ||
} | ||
|
||
# Load and run shUnit2. | ||
. tests/shunit2 |
Oops, something went wrong.