summaryrefslogtreecommitdiff
path: root/tests-clar/online/push.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar/online/push.c')
-rw-r--r--tests-clar/online/push.c89
1 files changed, 56 insertions, 33 deletions
diff --git a/tests-clar/online/push.c b/tests-clar/online/push.c
index 4c0a28c1c..05cef56e7 100644
--- a/tests-clar/online/push.c
+++ b/tests-clar/online/push.c
@@ -17,6 +17,8 @@ static char *_remote_url;
static char *_remote_user;
static char *_remote_pass;
+static int cred_acquire_cb(git_cred **, const char *, const char *, unsigned int, void *);
+
static git_remote *_remote;
static bool _cred_acquire_called;
static record_callbacks_data _record_cbs_data = {{ 0 }};
@@ -294,7 +296,6 @@ void test_online_push__initialize(void)
if (_remote_url) {
cl_git_pass(git_remote_create(&_remote, _repo, "test", _remote_url));
- git_remote_set_cred_acquire_cb(_remote, cred_acquire_cb, &_cred_acquire_called);
record_callbacks_data_clear(&_record_cbs_data);
git_remote_set_callbacks(_remote, &_record_cbs);
@@ -326,7 +327,7 @@ void test_online_push__initialize(void)
/* Now that we've deleted everything, fetch from the remote */
cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_FETCH));
- cl_git_pass(git_remote_download(_remote, NULL, NULL));
+ cl_git_pass(git_remote_download(_remote));
cl_git_pass(git_remote_update_tips(_remote));
git_remote_disconnect(_remote);
} else
@@ -348,6 +349,18 @@ void test_online_push__cleanup(void)
cl_git_sandbox_cleanup();
}
+static void push_pack_progress_cb(int stage, unsigned int current, unsigned int total, void* payload)
+{
+ int *was_called = (int *) payload;
+ *was_called = 1;
+}
+
+static void push_transfer_progress_cb(unsigned int current, unsigned int total, size_t bytes, void* payload)
+{
+ int *was_called = (int *) payload;
+ *was_called = 1;
+}
+
/**
* Calls push and relists refs on remote to verify success.
*
@@ -356,15 +369,17 @@ void test_online_push__cleanup(void)
* @param expected_refs expected remote refs after push
* @param expected_refs_len length of expected_refs
* @param expected_ret expected return value from git_push_finish()
+ * @param check_progress_cb Check that the push progress callbacks are called
*/
static void do_push(const char *refspecs[], size_t refspecs_len,
push_status expected_statuses[], size_t expected_statuses_len,
- expected_ref expected_refs[], size_t expected_refs_len, int expected_ret)
+ expected_ref expected_refs[], size_t expected_refs_len, int expected_ret, int check_progress_cb)
{
git_push *push;
git_push_options opts = GIT_PUSH_OPTIONS_INIT;
size_t i;
int ret;
+ int pack_progress_called = 0, transfer_progress_called = 0;
if (_remote) {
/* Auto-detect the number of threads to use */
@@ -375,6 +390,9 @@ static void do_push(const char *refspecs[], size_t refspecs_len,
cl_git_pass(git_push_new(&push, _remote));
cl_git_pass(git_push_set_options(push, &opts));
+ if (check_progress_cb)
+ cl_git_pass(git_push_set_callbacks(push, push_pack_progress_cb, &pack_progress_called, push_transfer_progress_cb, &transfer_progress_called));
+
for (i = 0; i < refspecs_len; i++)
cl_git_pass(git_push_add_refspec(push, refspecs[i]));
@@ -387,6 +405,11 @@ static void do_push(const char *refspecs[], size_t refspecs_len,
cl_assert_equal_i(1, git_push_unpack_ok(push));
}
+ if (check_progress_cb) {
+ cl_assert_equal_i(1, pack_progress_called);
+ cl_assert_equal_i(1, transfer_progress_called);
+ }
+
do_verify_push_status(push, expected_statuses, expected_statuses_len);
cl_assert_equal_i(expected_ret, ret);
@@ -405,7 +428,7 @@ static void do_push(const char *refspecs[], size_t refspecs_len,
/* Call push_finish() without ever calling git_push_add_refspec() */
void test_online_push__noop(void)
{
- do_push(NULL, 0, NULL, 0, NULL, 0, 0);
+ do_push(NULL, 0, NULL, 0, NULL, 0, 0, 0);
}
void test_online_push__b1(void)
@@ -415,7 +438,7 @@ void test_online_push__b1(void)
expected_ref exp_refs[] = { { "refs/heads/b1", &_oid_b1 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__b2(void)
@@ -425,7 +448,7 @@ void test_online_push__b2(void)
expected_ref exp_refs[] = { { "refs/heads/b2", &_oid_b2 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__b3(void)
@@ -435,7 +458,7 @@ void test_online_push__b3(void)
expected_ref exp_refs[] = { { "refs/heads/b3", &_oid_b3 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__b4(void)
@@ -445,7 +468,7 @@ void test_online_push__b4(void)
expected_ref exp_refs[] = { { "refs/heads/b4", &_oid_b4 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__b5(void)
@@ -455,7 +478,7 @@ void test_online_push__b5(void)
expected_ref exp_refs[] = { { "refs/heads/b5", &_oid_b5 } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__multi(void)
@@ -483,7 +506,7 @@ void test_online_push__multi(void)
};
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__implicit_tgt(void)
@@ -501,10 +524,10 @@ void test_online_push__implicit_tgt(void)
do_push(specs1, ARRAY_SIZE(specs1),
exp_stats1, ARRAY_SIZE(exp_stats1),
- exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1);
do_push(specs2, ARRAY_SIZE(specs2),
exp_stats2, ARRAY_SIZE(exp_stats2),
- exp_refs2, ARRAY_SIZE(exp_refs2), 0);
+ exp_refs2, ARRAY_SIZE(exp_refs2), 0, 0);
}
void test_online_push__fast_fwd(void)
@@ -526,19 +549,19 @@ void test_online_push__fast_fwd(void)
do_push(specs_init, ARRAY_SIZE(specs_init),
exp_stats_init, ARRAY_SIZE(exp_stats_init),
- exp_refs_init, ARRAY_SIZE(exp_refs_init), 0);
+ exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 1);
do_push(specs_ff, ARRAY_SIZE(specs_ff),
exp_stats_ff, ARRAY_SIZE(exp_stats_ff),
- exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0);
+ exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0);
do_push(specs_reset, ARRAY_SIZE(specs_reset),
exp_stats_init, ARRAY_SIZE(exp_stats_init),
- exp_refs_init, ARRAY_SIZE(exp_refs_init), 0);
+ exp_refs_init, ARRAY_SIZE(exp_refs_init), 0, 0);
do_push(specs_ff_force, ARRAY_SIZE(specs_ff_force),
exp_stats_ff, ARRAY_SIZE(exp_stats_ff),
- exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0);
+ exp_refs_ff, ARRAY_SIZE(exp_refs_ff), 0, 0);
}
void test_online_push__tag_commit(void)
@@ -548,7 +571,7 @@ void test_online_push__tag_commit(void)
expected_ref exp_refs[] = { { "refs/tags/tag-commit", &_tag_commit } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__tag_tree(void)
@@ -558,7 +581,7 @@ void test_online_push__tag_tree(void)
expected_ref exp_refs[] = { { "refs/tags/tag-tree", &_tag_tree } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__tag_blob(void)
@@ -568,7 +591,7 @@ void test_online_push__tag_blob(void)
expected_ref exp_refs[] = { { "refs/tags/tag-blob", &_tag_blob } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__tag_lightweight(void)
@@ -578,7 +601,7 @@ void test_online_push__tag_lightweight(void)
expected_ref exp_refs[] = { { "refs/tags/tag-lightweight", &_tag_lightweight } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
}
void test_online_push__tag_to_tag(void)
@@ -588,7 +611,7 @@ void test_online_push__tag_to_tag(void)
expected_ref exp_refs[] = { { "refs/tags/tag-tag", &_tag_tag } };
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 0);
}
void test_online_push__force(void)
@@ -605,16 +628,16 @@ void test_online_push__force(void)
do_push(specs1, ARRAY_SIZE(specs1),
exp_stats1, ARRAY_SIZE(exp_stats1),
- exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1);
do_push(specs2, ARRAY_SIZE(specs2),
NULL, 0,
- exp_refs1, ARRAY_SIZE(exp_refs1), GIT_ENONFASTFORWARD);
+ exp_refs1, ARRAY_SIZE(exp_refs1), GIT_ENONFASTFORWARD, 0);
/* Non-fast-forward update with force should pass. */
do_push(specs2_force, ARRAY_SIZE(specs2_force),
exp_stats2_force, ARRAY_SIZE(exp_stats2_force),
- exp_refs2_force, ARRAY_SIZE(exp_refs2_force), 0);
+ exp_refs2_force, ARRAY_SIZE(exp_refs2_force), 0, 1);
}
void test_online_push__delete(void)
@@ -645,7 +668,7 @@ void test_online_push__delete(void)
do_push(specs1, ARRAY_SIZE(specs1),
exp_stats1, ARRAY_SIZE(exp_stats1),
- exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 1);
/* When deleting a non-existent branch, the git client sends zero for both
* the old and new commit id. This should succeed on the server with the
@@ -655,23 +678,23 @@ void test_online_push__delete(void)
*/
do_push(specs_del_fake, ARRAY_SIZE(specs_del_fake),
exp_stats_fake, 1,
- exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0);
do_push(specs_del_fake_force, ARRAY_SIZE(specs_del_fake_force),
exp_stats_fake, 1,
- exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0);
/* Delete one of the pushed branches. */
do_push(specs_delete, ARRAY_SIZE(specs_delete),
exp_stats_delete, ARRAY_SIZE(exp_stats_delete),
- exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0);
+ exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0);
/* Re-push branches and retry delete with force. */
do_push(specs1, ARRAY_SIZE(specs1),
exp_stats1, ARRAY_SIZE(exp_stats1),
- exp_refs1, ARRAY_SIZE(exp_refs1), 0);
+ exp_refs1, ARRAY_SIZE(exp_refs1), 0, 0);
do_push(specs_delete_force, ARRAY_SIZE(specs_delete_force),
exp_stats_delete, ARRAY_SIZE(exp_stats_delete),
- exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0);
+ exp_refs_delete, ARRAY_SIZE(exp_refs_delete), 0, 0);
}
void test_online_push__bad_refspecs(void)
@@ -703,11 +726,11 @@ void test_online_push__expressions(void)
/* TODO: Find a more precise way of checking errors than a exit code of -1. */
do_push(specs_left_expr, ARRAY_SIZE(specs_left_expr),
NULL, 0,
- NULL, 0, -1);
+ NULL, 0, -1, 0);
do_push(specs_right_expr, ARRAY_SIZE(specs_right_expr),
exp_stats_right_expr, ARRAY_SIZE(exp_stats_right_expr),
- NULL, 0, 0);
+ NULL, 0, 0, 1);
}
void test_online_push__notes(void)
@@ -727,7 +750,7 @@ void test_online_push__notes(void)
do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
- exp_refs, ARRAY_SIZE(exp_refs), 0);
+ exp_refs, ARRAY_SIZE(exp_refs), 0, 1);
git_signature_free(signature);
}