diff options
author | KatolaZ <katolaz@freaknet.org> | 2017-08-10 01:06:56 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2017-08-10 01:06:56 +0100 |
commit | b0c7105a7f08389e012ce4882b38030df54cf474 (patch) | |
tree | 820c751e886efd7b4843643c391f4fed1a0b46b3 | |
parent | 33b7c33ab447a0463e414c6cf8f9a2cd2d047a20 (diff) |
added more tests -- commits without scorsh-commands
-rw-r--r-- | commits.go | 4 | ||||
-rwxr-xr-x | test/create_empty_commits.sh | 60 | ||||
-rw-r--r-- | test/scorsh_functions | 13 | ||||
-rw-r--r-- | test/test_spec | 11 | ||||
-rw-r--r-- | workers.go | 2 |
5 files changed, 81 insertions, 9 deletions
@@ -146,7 +146,7 @@ func walkCommits(msg spoolMsg, w *worker) error { oldrevCommit, err := repo.LookupCommit(oldRevOid) if err != nil { fmt.Fprintf(os.Stderr, "Commit: %s does not exist\n", oldRev) - return SCORSHerr(errNoCommit) + return fmt.Errorf("%s: %s", SCORSHerr(errNoCommit), oldRev) } newRevOid, _ := git.NewOid(newRev) @@ -154,7 +154,7 @@ func walkCommits(msg spoolMsg, w *worker) error { newrevCommit, err := repo.LookupCommit(newRevOid) if err != nil { fmt.Fprintf(os.Stderr, "Commit: %s does not exist\n", newRev) - return SCORSHerr(errNoCommit) + return fmt.Errorf("%s: %s", SCORSHerr(errNoCommit), newRev) } curCommit := newrevCommit diff --git a/test/create_empty_commits.sh b/test/create_empty_commits.sh new file mode 100755 index 0000000..6f6a7f8 --- /dev/null +++ b/test/create_empty_commits.sh @@ -0,0 +1,60 @@ +#!/bin/sh + +. ./scorsh_functions + +LINE_FILE=.line_file +cd ${SCORSH_APP} +LAST_LINE=$(wc -l scorsh.log | cut -d " " -f 1) +echo ${LAST_LINE} > ${LINE_FILE} +cd - > /dev/null + +### create an empty git commit without a scorsh-command the first +### commit will be ignored by scorsh for the moment, due to an error +### on the 0000...0000 oid +cd ${LOCAL_REPO} +git commit --allow-empty -m "this is an empty commit" +check "[ $? -eq 0 ]" $0 "create_first_commit" + +LAST_LINE=$(cat ${SCORSH_APP}/${LINE_FILE}) +git push + +cd - > /dev/null + +cd ${SCORSH_APP} +ret=$(tail -n +${LAST_LINE} scorsh.log | grep -c "Invalid commit ID") +sleep 1 +LAST_LINE=$(wc -l scorsh.log | cut -d " " -f 1) +echo ${LAST_LINE} > ${LINE_FILE} +cd - > /dev/null + +check "[ \"$ret\" = \"2\" ] " $0 "check_first_commit" + +### create two more commits without scorsh-commands +cd ${LOCAL_REPO} +git commit --allow-empty -m "second commit" +check "[ $? -eq 0 ]" $0 "create_second_commit" +git commit --allow-empty -m "third commit" +check "[ $? -eq 0 ]" $0 "create_third_commit" + +LAST_LINE=$(cat ${SCORSH_APP}/${LINE_FILE}) +commits=$(git log | grep "^commit " | cut -d " " -f 2 | head -2) +message_id=$(git push | grep "remote: id:" | cut -d " " -f 3) +cd - > /dev/null + +cd ${SCORSH_APP} +sleep 1 +for c in ${commits}; do + ret=$(tail -n +${LAST_LINE} scorsh.log | grep -c "error parsing commit ${c}: no SCORSH message found") + check "[ \"$ret\" = \"2\" ]" $0 "process_empty_commit" +done + +LAST_LINE=$(wc -l scorsh.log | cut -d " " -f 1) +echo ${LAST_LINE} > ${LINE_FILE} +cd - > /dev/null + + +##check_fatal "[ 1 -eq 0 ]" $0 "abort_on_purpose" + +rm ${LINE_FILE} + +return_results diff --git a/test/scorsh_functions b/test/scorsh_functions index 7f4fb1b..e007f82 100644 --- a/test/scorsh_functions +++ b/test/scorsh_functions @@ -13,6 +13,17 @@ failed(){ } ## func +fatal(){ + + TEST_NAME="$1" + TEST_SECTION="$2" + + echo "[\033[7;31mFATAL\033[0m] -- ${TEST_NAME}:${TEST_SECTION} " + FAILED_TESTS=$((${FAILED_TESTS} + 1)) +} + + +## func passed(){ TEST_NAME="$1" @@ -52,7 +63,7 @@ check_fatal(){ if $(echo ${EXPR}) ; then passed ${TEST_NAME} ${TEST_SECTION} else - failed ${TEST_NAME} ${TEST_SECTION} + fatal ${TEST_NAME} ${TEST_SECTION} echo "Fatal test failed -- Aborting" exit 1 fi diff --git a/test/test_spec b/test/test_spec index f085e9f..840fd44 100644 --- a/test/test_spec +++ b/test/test_spec @@ -20,11 +20,12 @@ LOCAL_REPO=$(realpath "./testbed_repo") TESTS="\ -./create_testbed.sh \ -./configure_app.sh \ -./start_scorsh.sh \ -./stop_scorsh.sh \ -./destroy_testbed.sh \ +./create_testbed.sh \ +./configure_app.sh \ +./start_scorsh.sh \ +./create_empty_commits.sh \ +./stop_scorsh.sh \ +./destroy_testbed.sh \ " ##./destroy_testbed.sh \ @@ -106,7 +106,7 @@ func runWorker(w *worker) { // process message err := walkCommits(msg, w) if err != nil { - log.Printf("[worker: %s] error in walk_commits: %s", err) + log.Printf("[worker: %s] error in walk_commits: %s", w.Name, err) } w.StatusChan <- msg debug.log("[worker: %s] Sent message back: %s", w.Name, msg) |