8000 ci: update push options tests · russell/libgit2@85279f0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 85279f0

Browse files
< 8000 span class="pl-1">committed
ci: update push options tests
Keep the push options tests more constrained to our CI environment; writing files within the test sandbox instead of outside of it. Provide the path to the output file in the test data. In addition, add the repository to the test resources instead of recreating the hooks every time.
1 parent 3966995 commit 85279f0

File tree

13 files changed

+57
-58
lines changed

13 files changed

+57
-58
lines changed

ci/hooks/pre-receive

Lines changed: 0 additions & 2 deletions
This file was deleted.

ci/test.sh

Lines changed: 15 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -ex
3+
set -e
44< 8000 code class="diff-text syntax-highlighted-line">

55
if [ -n "$SKIP_TESTS" ]; then
66
if [ -z "$SKIP_OFFLINE_TESTS" ]; then SKIP_OFFLINE_TESTS=1; fi
@@ -162,14 +162,7 @@ echo ""
162162
if should_run "GITDAEMON_TESTS"; then
163163
echo "Starting git daemon (standard)..."
164164
GIT_STANDARD_DIR=`mktemp -d ${TMPDIR}/git_standard.XXXXXXXX`
165-
git init --bare "${GIT_STANDARD_DIR}/test.git" >/dev/null
166-
git config --file "${GIT_STANDARD_DIR}/test.git/config" receive.advertisePushOptions true
167-
for f in $(ls ${SOURCE_DIR}/ci/hooks)
168-
do
169-
sed "s=%file%=${TMPDIR}/push-option-result-git-daemon=g" "${SOURCE_DIR}/ci/hooks/$f" > "${GIT_STANDARD_DIR}/test.git/hooks/${f}"
170-
chmod +x "$GIT_STANDARD_DIR/test.git/hooks/${f}"
171-
done
172-
165+
cp -R "${SOURCE_DIR}/tests/resources/pushoptions.git" "${GIT_STANDARD_DIR}/test.git"
173166
git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GIT_STANDARD_DIR}" "${GIT_STANDARD_DIR}" 2>/dev/null &
174167
175168
GIT_STANDARD_PID=$!
@@ -204,14 +197,7 @@ if should_run "NTLM_TESTS" || should_run "ONLINE_TESTS"; then
204197
205198
echo "Starting HTTP server..."
206199
HTTP_DIR=`mktemp -d ${TMPDIR}/http.XXXXXXXX`
207-
git init --bare "${HTTP_DIR}/test.git"
208-
git config --file "${HTTP_DIR}/test.git/config" receive.advertisePushOptions true
209-
210-
for f in $(ls ${SOURCE_DIR}/ci/hooks)
211-
do
212-
sed "s=%file%=${TMPDIR}/push-option-result-git-ntlm=g" "${SOURCE_DIR}/ci/hooks/$f" > "${HTTP_DIR}/test.git/hooks/${f}"
213-
chmod +x "$HTTP_DIR/test.git/hooks/${f}"
214-
done
200+
cp -R "${SOURCE_DIR}/tests/resources/pushoptions.git" "${HTTP_DIR}/test.git"
215201
216202
java -jar poxygit.jar --address 127.0.0.1 --port 9000 --credentials foo:baz --quiet "${HTTP_DIR}" &
217203
HTTP_PID=$!
@@ -220,14 +206,8 @@ fi
220206
if should_run "SSH_TESTS"; then
221207
echo "Starting SSH server..."
222208
SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
223-
git init --bare "${SSHD_DIR}/test.git" >/dev/null
224-
git config --file "${SSHD_DIR}/test.git/config" receive.advertisePushOptions true
225-
226-
for f in $(ls ${SOURCE_DIR}/ci/hooks)
227-
do
228-
sed "s=%file%=${TMPDIR}/push-option-result-git-ssh=g" "${SOURCE_DIR}/ci/hooks/$f" > "${SSHD_DIR}/test.git/hooks/${f}"
229-
chmod +x "$SSHD_DIR/test.git/hooks/${f}"
230-
done
209+
cp -R "${SOURCE_DIR}/tests/resources/pushoptions.git" "${SSHD_DIR}/test.git"
210+
ls -FlasR "${SSHD_DIR}"
231211
232212
cat >"${SSHD_DIR}/sshd_config" <<-EOF
233213
Port 2222
@@ -344,13 +324,11 @@ if should_run "GITDAEMON_TESTS"; then
344324
echo "Running gitdaemon (standard) tests"
345325
echo ""
346326
347-
if [[ "$RUN_PUSH_OPTONS_TESTS" = "true " ]]; then
348-
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-git-daemon"
349-
fi
350327
export GITTEST_REMOTE_URL="git://localhost/test.git"
328+
export GITTEST_PUSH_OPTIONS=true
351329
run_test gitdaemon
352-
unset GITTEST_PUSH_OPTION_RESULT
353330
unset GITTEST_REMOTE_URL
331+
unset GITTEST_PUSH_OPTIONS
354332
355333
echo ""
356334
echo "Running gitdaemon (namespace) tests"
@@ -402,33 +380,29 @@ if should_run "NTLM_TESTS"; then
402380
echo "Running NTLM tests (IIS emulation)"
403381
echo ""
404382
405-
if [[ "$RUN_PUSH_OPTONS_TESTS" = "true " ]]; then
406-
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-git-ntlm"
407-
fi
408383
export GITTEST_REMOTE_URL="http://localhost:9000/ntlm/test.git"
409384
export GITTEST_REMOTE_USER="foo"
410385
export GITTEST_REMOTE_PASS="baz"
386+
export GITTEST_PUSH_OPTIONS=true
411387
run_test auth_clone_and_push
412-
unset GITTEST_PUSH_OPTION_RESULT
413388
unset GITTEST_REMOTE_URL
414389
unset GITTEST_REMOTE_USER
415390
unset GITTEST_REMOTE_PASS
391+
unset GITTEST_PUSH_OPTIONS
416392
417393
echo ""
418394
echo "Running NTLM tests (Apache emulation)"
419395
echo ""
420396
421-
if [[ "$RUN_PUSH_OPTONS_TESTS" == "true " ]]; then
422-
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-git-ntlm"
423-
fi
424397
export GITTEST_REMOTE_URL="http://localhost:9000/broken-ntlm/test.git"
425398
export GITTEST_REMOTE_USER="foo"
426399
export GITTEST_REMOTE_PASS="baz"
400+
export GITTEST_PUSH_OPTIONS=true
427401
run_test auth_clone_and_push
428-
unset GITTEST_PUSH_OPTION_RESULT
429402
unset GITTEST_REMOTE_URL
430403
unset GITTEST_REMOTE_USER
431404
unset GITTEST_REMOTE_PASS
405+
unset GITTEST_PUSH_OPTIONS
432406
fi
433407
434408
if should_run "NEGOTIATE_TESTS" && -n "$GITTEST_NEGOTIATE_PASSWORD" ; then
@@ -477,25 +451,21 @@ if should_run "SSH_TESTS"; then
477451
echo "Running ssh tests"
478452
echo ""
479453
480-
if [[ "$RUN_PUSH_OPTONS_TESTS" == "true " ]]; then
481-
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-ssh"
482-
fi
483454
export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
455+
export GITTEST_PUSH_OPTIONS=true
484456
run_test ssh
485-
unset GITTEST_PUSH_OPTION_RESULT
486457
unset GITTEST_REMOTE_URL
458+
unset GITTEST_PUSH_OPTIONS
487459
488460
echo ""
489461
echo "Running ssh tests (scp-style paths)"
490462
echo ""
491463
492-
if [[ "$RUN_PUSH_OPTONS_TESTS" == "true " ]]; then
493-
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-ssh"
494-
fi
495464
export GITTEST_REMOTE_URL="[localhost:2222]:$SSHD_DIR/test.git"
465+
export GITTEST_PUSH_OPTIONS=true
496466
run_test ssh
497-
unset GITTEST_PUSH_OPTION_RESULT
498467
unset GITTEST_REMOTE_URL
468+
unset GITTEST_PUSH_OPTIONS
499469
500470
unset GITTEST_SSH_CMD
501471

tests/libgit2/online/push.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ static char *_remote_ssh_passphrase = NULL;
2121
static char *_remote_default = NULL;
2222
static char *_remote_expectcontinue = NULL;
2323

24+
static char *_remote_push_options = NULL;
25+
2426
static char *_orig_ssh_cmd = NULL;
2527
static char *_ssh_cmd = NULL;
2628

27-
static char *_remote_push_options_result = NULL;
28-
2929
static int cred_acquire_cb(git_credential **, const char *, const char *, unsigned int, void *);
3030

3131
static git_remote *_remote;
@@ -373,7 +373,7 @@ void test_online_push__initialize(void)
373373
_remote_ssh_passphrase = cl_getenv("GITTEST_REMOTE_SSH_PASSPHRASE");
374374
_remote_default = cl_getenv("GITTEST_REMOTE_DEFAULT");
375375
_remote_expectcontinue = cl_getenv("GITTEST_REMOTE_EXPECTCONTINUE");
376-
_remote_push_options_result = cl_getenv("GITTEST_PUSH_OPTION_RESULT");
376+
_remote_push_options = cl_getenv("GITTEST_PUSH_OPTIONS");
377377
_remote = NULL;
378378

379379
_orig_ssh_cmd = cl_getenv("GIT_SSH");
@@ -437,7 +437,7 @@ void test_online_push__cleanup(void)
437437
git__free(_remote_ssh_passphrase);
438438
git__free(_remote_default);
439439
git__free(_remote_expectcontinue);
440-
git__free(_remote_push_options_result);
440+
git__free(_remote_push_options);
441441

442442
git__free(_orig_ssh_cmd);
443443
git__free(_ssh_cmd);
@@ -449,6 +449,7 @@ void test_online_push__cleanup(void)
449449

450450
record_callbacks_data_clear(&_record_cbs_data);
451451

452+
cl_fixture_cleanup("push-options-result");
452453
cl_fixture_cleanup("testrepo.git");
453454
cl_git_sandbox_cleanup();
454455
}
@@ -827,30 +828,41 @@ void test_online_push__force(void)
827828
NULL);
828829
}
829830

830-
static void push_option_test(git_strarray push_options, const char *expected_option)
831+
static void push_option_test(git_strarray given_options, const char *expected_option)
831832
{
832833
const char *specs[] = { "refs/heads/b1:refs/heads/b1" };
833834
push_status exp_stats[] = { { "refs/heads/b1", 1 } };
834835
expected_ref exp_refs[] = { { "refs/heads/b1", &_oid_b1 } };
836+
git_str push_options_path = GIT_STR_INIT;
835837
git_str push_options_result = GIT_STR_INIT;
838+
char *options[16];
839+
git_strarray push_options = { options, given_options.count + 1 };
840+
size_t i;
836841

837842
/* Skip the test if we're missing the push options result file */
838-
if (!_remote_push_options_result)
843+
if (!_remote_push_options)
839844
cl_skip();
840845

846+
cl_assert(given_options.count < 16);
847+
848+
cl_git_pass(git_str_joinpath(&push_options_path, clar_sandbox_path(), "push-options-result"));
849+
850+
options[0] = push_options_path.ptr;
851+
for (i = 0; i < given_options.count; i++)
852+
options[i + 1] = given_options.strings[i];
853+
841854
do_push(specs, ARRAY_SIZE(specs),
842855
exp_stats, ARRAY_SIZE(exp_stats),
843856
exp_refs, ARRAY_SIZE(exp_refs),
844857
0, 1, 1,
845858
&push_options);
846859

847-
if (git_futils_readbuffer(&push_options_result, _remote_push_options_result) < 0)
848-
cl_fail("Failed to read push options result file");
849-
850-
cl_assert_equal_strn(expected_option, git_str_cstr(&push_options_result),
851-
strlen(expected_option));
860+
cl_assert(git_fs_path_exists(pus F438 h_options_path.ptr));
861+
cl_git_pass(git_futils_readbuffer(&push_options_result, push_options_path.ptr));
852862

863+
cl_assert_equal_s(expected_option, git_str_cstr(&push_options_result));
853864
git_str_dispose(&push_options_result);
865+
git_str_dispose(&push_options_path);
854866
}
855867

856868
void test_online_push__options(void)

tests/resources/pushoptions.git/HEAD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/main

tests/resources/pushoptions.git/branches/.gitignore

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = true
5+
ignorecase = true
6+
precomposeunicode = true
7+
[receive]
8+
advertisePushOptions = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
printf "${GIT_PUSH_OPTION_1}${GIT_PUSH_OPTION_2}${GIT_PUSH_OPTION_3}" > "${GIT_PUSH_OPTION_0}"
3+
exit 0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# git ls-files --others --exclude-from=.git/info/exclude
2+
# Lines that start with '#' are comments.
3+
# For a project mostly in C, the following would be a good set of
4+
# exclude patterns (uncomment them if you want to use them):
5+
# *.[oa]
6+
# *~

tests/resources/pushoptions.git/objects/info/.gitignore

Whitespace-only changes.

0 commit comments

Comments
 (0)
0