commit 914bfd3ddbdf1adc0adf828c7531b8174b6b2010 from: Omar Polo date: Thu Mar 28 15:23:17 2024 UTC http_notification.sh: add a testcase add test_branch_created(). at the moment this is not different from a "normal" commit notification but it'll change in the future and it's handy to have it for an upcoming branch removed notification. commit - 936239010f884c916c0f8680490fea91813b5334 commit + 914bfd3ddbdf1adc0adf828c7531b8174b6b2010 blob - a83c9622d1b9c26800dad3d240170b2a0e2798c6 blob + 108cbb93e5ac5409668ac95f07850296d69a9b9c --- regress/gotd/http_notification.sh +++ regress/gotd/http_notification.sh @@ -338,7 +338,98 @@ test_many_commits_summarized() { EOF done >> $testroot/stdout.expected echo "]}" >> $testroot/stdout.expected + ed -s "$testroot/stdout.expected" <<-EOF + ,j + w + EOF + + cmp -s $testroot/stdout.expected $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + test_done "$testroot" "$ret" +} + +test_branch_created() { + local testroot=`test_init branch_created 1` + + got clone -a -q ${GOTD_TEST_REPO_URL} $testroot/repo-clone + ret=$? + if [ $ret -ne 0 ]; then + echo "got clone failed unexpectedly" >&2 + test_done "$testroot" 1 + return 1 + fi + + got checkout -q $testroot/repo-clone $testroot/wt >/dev/null + ret=$? + if [ $ret -ne 0 ]; then + echo "got checkout failed unexpectedly" >&2 + test_done "$testroot" 1 + return 1 + fi + + (cd $testroot/wt && got branch newbranch > /dev/null) + + echo "change alpha on branch" > $testroot/wt/alpha + (cd $testroot/wt && got commit -m 'newbranch' > /dev/null) + local commit_id=`git_show_branch_head $testroot/repo-clone newbranch` + local author_time=`git_show_author_time $testroot/repo-clone $commit_id` + + timeout 5 ./http-server -p "$GOTD_TEST_HTTP_PORT" \ + > $testroot/stdout & + + got send -b newbranch -q -r $testroot/repo-clone + ret=$? + if [ $ret -ne 0 ]; then + echo "got send failed unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + + wait %1 # wait for the http "server" + + d=`date -u -r $author_time +"%a %b %e %X %Y UTC"` + + # in the future it should contain something like this too + # { + # "type":"new-branch", + # "user":"${GOTD_DEVUSER}", + # "ref":"refs/heads/newbranch" + # }, + + touch "$testroot/stdout.expected" ed -s "$testroot/stdout.expected" <<-EOF + a + {"notifications":[ + { + "type":"commit", + "short":false, + "id":"$commit_id", + "author":{ + "full":"$GOT_AUTHOR", + "name":"$GIT_AUTHOR_NAME", + "mail":"$GIT_AUTHOR_EMAIL", + "user":"$GOT_AUTHOR_11" + }, + "committer":{ + "full":"$GOT_AUTHOR", + "name":"$GIT_AUTHOR_NAME", + "mail":"$GIT_AUTHOR_EMAIL", + "user":"$GOT_AUTHOR_11" + }, + "date":"$d", + "short_message":"newbranch", + "message":"newbranch\n", + "diffstat":{}, + "changes":{} + } + ]} + . ,j w EOF @@ -359,3 +450,4 @@ run_test test_file_changed run_test test_bad_utf8 run_test test_many_commits_not_summarized run_test test_many_commits_summarized +run_test test_branch_created