Skip to content

Commit

Permalink
"refactored the code"
Browse files Browse the repository at this point in the history
  • Loading branch information
Josee9988 committed Jul 8, 2021
1 parent 34da14d commit 446e720
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 37 deletions.
102 changes: 77 additions & 25 deletions tests/custom_data_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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() {
Expand All @@ -15,7 +16,7 @@ oneTimeSetUp() {
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 $OMIT_STR >/dev/null
bash SETUP_TEMPLATE.sh $USERNAME $NAME $MAIL $TYPE $OMIT_STR >/dev/null
}

oneTimeTearDown() {
Expand All @@ -24,44 +25,95 @@ oneTimeTearDown() {

# TESTS
suite() {
suite_addTest testDotGithubISSUE_TEMPLATEAsignees
suite_addTest testDotGithubISSUE_TEMPLATEConfig
suite_addTest testDotGithubConfig
suite_addTest testDotGithubSecurity
suite_addTest testDotGithubCODEOWNERS
suite_addTest testDotGitignore
suite_addTest testDotChangelog
}

testDotGithubISSUE_TEMPLATEAsignees() {
isTheAssigneeNotFound=0
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")

suite_addTest testDotGithubFolder
suite_addTest testDotGithubISSUE_TEMPLATE
suite_addTest testDotGithubISSUE_TEMPLATEFiles
suite_addTest testDotGithubFiles
for file in "${files[@]}"; do
if ! grep -q "$assigneesWithName" "$file"; then
isTheAssigneeNotFound=1
fi
done
assertNotEquals 1 $isTheAssigneeNotFound
}

testDotGithubFolder() {
githubFolderFound=0
if [ -e ".github/" ]; then
githubFolderFound=1
testDotGithubISSUE_TEMPLATEConfig() {
isTheAssigneeNotFound=0
mailInConfig="url: mailto:$MAIL"

if grep -q "$mailInConfig" ".github/ISSUE_TEMPLATE/config.yml"; then
isTheAssigneeNotFound=1
fi
assertEquals 1 $githubFolderFound
assertEquals 1 $isTheAssigneeNotFound
}

testDotGithubConfig() {
isNewIssueWelcomeCommentFound=0
newIssueWelcomeComment="Thanks for opening your first issue in $USERNAME/$NAME! Be sure to"

if grep -q "$newIssueWelcomeComment" ".github/config.yml"; then
isNewIssueWelcomeCommentFound=1
fi
assertEquals 1 $isNewIssueWelcomeCommentFound
}

testDotGithubISSUE_TEMPLATE() {
folderFound=0
if [ -e ".github/ISSUE_TEMPLATE" ]; then
folderFound=1
testDotGithubSecurity() {
isSecurityDataFound=0
securityData1="(mailto:$MAIL)"
securityData2="[$MAIL]"
securityData3="he project's team and community take security issues"

if grep -q "$securityData1" ".github/SECURITY.md" && grep -q "$securityData2" ".github/SECURITY.md" && grep -q "$securityData3" ".github/SECURITY.md"; then
isSecurityDataFound=1
fi
assertEquals 1 $folderFound
assertEquals 1 $isSecurityDataFound
}

testDotGithubISSUE_TEMPLATEFiles() {
filesFound=0
if [ -e ".github/ISSUE_TEMPLATE/1-bug-report.md" ] && [ -e ".github/ISSUE_TEMPLATE/2-failing-test.md" ] && [ -e ".github/ISSUE_TEMPLATE/3-docs-bug.md" ] && [ -e ".github/ISSUE_TEMPLATE/4-feature-request.md" ] && [ -e ".github/ISSUE_TEMPLATE/5-enhancement-request.md" ] && [ -e ".github/ISSUE_TEMPLATE/6-security-report.md" ] && [ -e ".github/ISSUE_TEMPLATE/7-question-support.md" ] && [ -e ".github/ISSUE_TEMPLATE/config.yml" ]; then
filesFound=1
testDotGithubCODEOWNERS() {
isCodeownersDataFound=0
usernameData="$USERNAME"

if grep -q "$usernameData" ".github/CODEOWNERS"; then
isCodeownersDataFound=1
fi
assertEquals 1 $isCodeownersDataFound
}

testDotGitignore() {
isGitignoreDataFound=0
gitignoreData1="###> $USERNAME/$NAME ###"
gitignoreData2="###< $USERNAME/$NAME ###"

if grep -q "$gitignoreData1" ".gitignore" && grep -q "$gitignoreData2" ".gitignore"; then
isGitignoreDataFound=1
fi
assertEquals 1 $filesFound
assertEquals 1 $isGitignoreDataFound
}

testDotGithubFiles() {
filesFound=0
if [ -e ".github/CODEOWNERS" ] && [ -e ".github/CODE_OF_CONDUCT.md" ] && [ -e ".github/CONTRIBUTING.md" ] && [ -e ".github/ISSUE_TEMPLATE.md" ] && [ -e ".github/pull_request_template.md" ] && [ -e ".github/SECURITY.md" ] && [ -e ".github/SUPPORT.md" ] && [ -e ".github/issue_label_bot.yaml" ] && [ -e ".github/config.yml" ] && [ -e ".github/FUNDING.yml" ] && [ -e ".github/settings.yml" ]; then
filesFound=1
testDotChangelog() {
isChangelogDataFound=0
changelogData1="All notable changes to the"
changelogData2="**$NAME**"
changelogData3="$TYPE will be documented in this file."

if grep -q "$changelogData1" "CHANGELOG.md" && grep -q "$changelogData2" "CHANGELOG.md" && grep -q "$changelogData3" "CHANGELOG.md"; then
isChangelogDataFound=1
fi
assertEquals 1 $filesFound
assertEquals 1 $isChangelogDataFound
}

# Load and run shUnit2.
Expand Down
30 changes: 18 additions & 12 deletions tests/project_scaffolding_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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() {
Expand All @@ -15,7 +16,7 @@ oneTimeSetUp() {
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 $OMIT_STR >/dev/null
bash SETUP_TEMPLATE.sh $USERNAME $NAME $MAIL $TYPE $OMIT_STR >/dev/null
}

oneTimeTearDown() {
Expand All @@ -39,7 +40,6 @@ testDotGithubFolder() {
githubFolderFound=1
fi
assertEquals 1 $githubFolderFound

}

testDotGithubISSUE_TEMPLATE() {
Expand All @@ -51,19 +51,25 @@ testDotGithubISSUE_TEMPLATE() {
}

testDotGithubISSUE_TEMPLATEFiles() {
filesFound=0
if [ -e ".github/ISSUE_TEMPLATE/1-bug-report.md" ] && [ -e ".github/ISSUE_TEMPLATE/2-failing-test.md" ] && [ -e ".github/ISSUE_TEMPLATE/3-docs-bug.md" ] && [ -e ".github/ISSUE_TEMPLATE/4-feature-request.md" ] && [ -e ".github/ISSUE_TEMPLATE/5-enhancement-request.md" ] && [ -e ".github/ISSUE_TEMPLATE/6-security-report.md" ] && [ -e ".github/ISSUE_TEMPLATE/7-question-support.md" ] && [ -e ".github/ISSUE_TEMPLATE/config.yml" ]; then
filesFound=1
fi
assertEquals 1 $filesFound
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() {
filesFound=0
if [ -e ".github/CODEOWNERS" ] && [ -e ".github/CODE_OF_CONDUCT.md" ] && [ -e ".github/CONTRIBUTING.md" ] && [ -e ".github/ISSUE_TEMPLATE.md" ] && [ -e ".github/pull_request_template.md" ] && [ -e ".github/SECURITY.md" ] && [ -e ".github/SUPPORT.md" ] && [ -e ".github/issue_label_bot.yaml" ] && [ -e ".github/config.yml" ] && [ -e ".github/FUNDING.yml" ] && [ -e ".github/settings.yml" ]; then
filesFound=1
fi
assertEquals 1 $filesFound
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() {
Expand Down

0 comments on commit 446e720

Please sign in to comment.