commit d3bfa9a153550bf95a0017f1ff8827181280d640 from: Stefan Sperling date: Wed Apr 17 16:57:13 2024 UTC add a basic test for HTTP protocol used with 'got fetch' commit - 449ea7f22083788e4dc012f4ab6649594f92a563 commit + d3bfa9a153550bf95a0017f1ff8827181280d640 blob - 609c219041bc3e37576915d5ae9e8f2cc180f7d7 blob + b04cd83f21f1e304ec03c28de75c23c253d1b352 --- regress/cmdline/fetch.sh +++ regress/cmdline/fetch.sh @@ -2019,7 +2019,123 @@ EOF test_done "$testroot" "$ret" } + +test_fetch_basic_http() { + local testroot=`test_init fetch_basic` + local testurl=http://127.0.0.1:$GOT_TEST_HTTP_PORT + local commit_id=`git_show_head $testroot/repo` + + timeout 5 ./http-server -p $GOT_TEST_HTTP_PORT $testroot \ + > $testroot/http-server.log & + + sleep 1 # server starts up + + got clone -q $testurl/repo $testroot/repo-clone + ret=$? + if [ $ret -ne 0 ]; then + echo "got clone command failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + echo "modified alpha" > $testroot/repo/alpha + git_commit $testroot/repo -m "modified alpha" + local commit_id2=`git_show_head $testroot/repo` + + got ref -l -r $testroot/repo-clone > $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + echo "got ref command failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + got fetch -q -r $testroot/repo-clone > $testroot/stdout \ + 2> $testroot/stderr + ret=$? + if [ $ret -ne 0 ]; then + echo "got fetch command failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + kill %1 + wait %1 # wait for http-server + + echo -n > $testroot/stdout.expected + + cmp -s $testroot/stdout $testroot/stdout.expected + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + got log -l0 -p -r $testroot/repo > $testroot/log-repo + ret=$? + if [ $ret -ne 0 ]; then + echo "got log command failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + got log -l0 -p -r $testroot/repo > $testroot/log-repo-clone + ret=$? + if [ $ret -ne 0 ]; then + echo "got log command failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + cmp -s $testroot/log-repo $testroot/log-repo-clone + ret=$? + if [ $ret -ne 0 ]; then + echo "log -p output of cloned repository differs" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + got ref -l -r $testroot/repo > $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + echo "got ref command failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + echo "HEAD: refs/heads/master" > $testroot/stdout.expected + echo "refs/heads/master: $commit_id2" >> $testroot/stdout.expected + + cmp -s $testroot/stdout $testroot/stdout.expected + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + got ref -l -r $testroot/repo-clone > $testroot/stdout + ret=$? + if [ $ret -ne 0 ]; then + echo "got ref command failed unexpectedly" >&2 + test_done "$testroot" "$ret" + return 1 + fi + + echo "HEAD: refs/heads/master" > $testroot/stdout.expected + echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected + echo "refs/remotes/origin/HEAD: refs/remotes/origin/master" \ + >> $testroot/stdout.expected + echo "refs/remotes/origin/master: $commit_id2" \ + >> $testroot/stdout.expected + + cmp -s $testroot/stdout $testroot/stdout.expected + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + test_parseargs "$@" run_test test_fetch_basic run_test test_fetch_list @@ -2038,3 +2154,4 @@ run_test test_fetch_gitconfig_remote_repo run_test test_fetch_delete_remote_refs run_test test_fetch_honor_wt_conf_bflag run_test test_fetch_from_out_of_date_remote +run_test test_fetch_basic_http