Commit 6eb9e39c by Carlos Martín Nieto

push: move main test function to git_remote_push()

We have the step-by-step method in the initialization function as we
want to remove references based on the list of references which are
already there, and we can use the convenience function for testing the
main push.
parent 3149547b
...@@ -89,46 +89,38 @@ static int cred_acquire_cb( ...@@ -89,46 +89,38 @@ static int cred_acquire_cb(
return -1; return -1;
} }
/* the results of a push status. when used for expected values, msg may be NULL
* to indicate that it should not be matched. */
typedef struct {
const char *ref;
int success;
const char *msg;
} push_status;
/** /**
* git_push_status_foreach callback that records status entries. * git_push_status_foreach callback that records status entries.
* @param data (git_vector *) of push_status instances * @param data (git_vector *) of push_status instances
*/ */
static int record_push_status_cb(const char *ref, const char *msg, void *data) static int record_push_status_cb(const char *ref, const char *msg, void *payload)
{ {
git_vector *statuses = (git_vector *)data; record_callbacks_data *data = (record_callbacks_data *) payload;
push_status *s; push_status *s;
cl_assert(s = git__malloc(sizeof(*s))); cl_assert(s = git__calloc(1, sizeof(*s)));
s->ref = ref; if (ref)
cl_assert(s->ref = git__strdup(ref));
s->success = (msg == NULL); s->success = (msg == NULL);
s->msg = msg; if (msg)
cl_assert(s->msg = git__strdup(msg));
git_vector_insert(statuses, s); git_vector_insert(&data->statuses, s);
return 0; return 0;
} }
static void do_verify_push_status(git_push *push, const push_status expected[], const size_t expected_len) static void do_verify_push_status(record_callbacks_data *data, const push_status expected[], const size_t expected_len)
{ {
git_vector actual = GIT_VECTOR_INIT; git_vector *actual = &data->statuses;
push_status *iter; push_status *iter;
bool failed = false; bool failed = false;
size_t i; size_t i;
git_push_status_foreach(push, record_push_status_cb, &actual); if (expected_len != actual->length)
if (expected_len != actual.length)
failed = true; failed = true;
else else
git_vector_foreach(&actual, i, iter) git_vector_foreach(actual, i, iter)
if (strcmp(expected[i].ref, iter->ref) || if (strcmp(expected[i].ref, iter->ref) ||
(expected[i].success != iter->success) || (expected[i].success != iter->success) ||
(expected[i].msg && (!iter->msg || strcmp(expected[i].msg, iter->msg)))) { (expected[i].msg && (!iter->msg || strcmp(expected[i].msg, iter->msg)))) {
...@@ -149,7 +141,7 @@ static void do_verify_push_status(git_push *push, const push_status expected[], ...@@ -149,7 +141,7 @@ static void do_verify_push_status(git_push *push, const push_status expected[],
git_buf_puts(&msg, "\nACTUAL:\n"); git_buf_puts(&msg, "\nACTUAL:\n");
git_vector_foreach(&actual, i, iter) { git_vector_foreach(actual, i, iter) {
if (iter->success) if (iter->success)
git_buf_printf(&msg, "%s: success\n", iter->ref); git_buf_printf(&msg, "%s: success\n", iter->ref);
else else
...@@ -161,10 +153,10 @@ static void do_verify_push_status(git_push *push, const push_status expected[], ...@@ -161,10 +153,10 @@ static void do_verify_push_status(git_push *push, const push_status expected[],
git_buf_free(&msg); git_buf_free(&msg);
} }
git_vector_foreach(&actual, i, iter) git_vector_foreach(actual, i, iter)
git__free(iter); git__free(iter);
git_vector_free(&actual); git_vector_free(actual);
} }
/** /**
...@@ -431,22 +423,24 @@ void test_online_push__cleanup(void) ...@@ -431,22 +423,24 @@ void test_online_push__cleanup(void)
static int push_pack_progress_cb( static int push_pack_progress_cb(
int stage, unsigned int current, unsigned int total, void* payload) int stage, unsigned int current, unsigned int total, void* payload)
{ {
int *calls = (int *)payload; record_callbacks_data *data = (record_callbacks_data *) payload;
GIT_UNUSED(stage); GIT_UNUSED(current); GIT_UNUSED(total); GIT_UNUSED(stage); GIT_UNUSED(current); GIT_UNUSED(total);
if (*calls < 0) if (data->pack_progress_calls < 0)
return *calls; return data->pack_progress_calls;
(*calls)++;
data->pack_progress_calls++;
return 0; return 0;
} }
static int push_transfer_progress_cb( static int push_transfer_progress_cb(
unsigned int current, unsigned int total, size_t bytes, void* payload) unsigned int current, unsigned int total, size_t bytes, void* payload)
{ {
int *calls = (int *)payload; record_callbacks_data *data = (record_callbacks_data *) payload;
GIT_UNUSED(current); GIT_UNUSED(total); GIT_UNUSED(bytes); GIT_UNUSED(current); GIT_UNUSED(total); GIT_UNUSED(bytes);
if (*calls < 0) if (data->transfer_progress_calls < 0)
return *calls; return data->transfer_progress_calls;
(*calls)++;
data->transfer_progress_calls++;
return 0; return 0;
} }
...@@ -466,62 +460,61 @@ static void do_push( ...@@ -466,62 +460,61 @@ static void do_push(
expected_ref expected_refs[], size_t expected_refs_len, expected_ref expected_refs[], size_t expected_refs_len,
int expected_ret, int check_progress_cb, int check_update_tips_cb) int expected_ret, int check_progress_cb, int check_update_tips_cb)
{ {
git_push *push;
git_push_options opts = GIT_PUSH_OPTIONS_INIT; git_push_options opts = GIT_PUSH_OPTIONS_INIT;
size_t i; size_t i;
int pack_progress_calls = 0, transfer_progress_calls = 0; int error;
git_strarray specs;
git_signature *pusher; git_signature *pusher;
git_remote_callbacks callbacks;
record_callbacks_data *data;
if (_remote) { if (_remote) {
/* Auto-detect the number of threads to use */ /* Auto-detect the number of threads to use */
opts.pb_parallelism = 0; opts.pb_parallelism = 0;
cl_git_pass(git_signature_now(&pusher, "Foo Bar", "foo@example.com")); cl_git_pass(git_signature_now(&pusher, "Foo Bar", "foo@example.com"));
cl_git_pass(git_remote_connect(_remote, GIT_DIRECTION_PUSH));
cl_git_pass(git_push_new(&push, _remote)); memcpy(&callbacks, git_remote_get_callbacks(_remote), sizeof(callbacks));
cl_git_pass(git_push_set_options(push, &opts)); data = callbacks.payload;
if (check_progress_cb) { callbacks.pack_progress = push_pack_progress_cb;
/* if EUSER, then abort in transfer */ callbacks.push_transfer_progress = push_transfer_progress_cb;
if (expected_ret == GIT_EUSER) callbacks.push_update_reference = record_push_status_cb;
transfer_progress_calls = GIT_EUSER; cl_git_pass(git_remote_set_callbacks(_remote, &callbacks));
cl_git_pass( specs.count = refspecs_len;
git_push_set_callbacks( specs.strings = git__calloc(refspecs_len, sizeof(char *));
push, push_pack_progress_cb, &pack_progress_calls, cl_assert(specs.strings);
push_transfer_progress_cb, &transfer_progress_calls));
}
for (i = 0; i < refspecs_len; i++) for (i = 0; i < refspecs_len; i++)
cl_git_pass(git_push_add_refspec(push, refspecs[i])); specs.strings[i] = (char *) refspecs[i];
/* if EUSER, then abort in transfer */
if (check_progress_cb && expected_ret == GIT_EUSER)
data->transfer_progress_calls = GIT_EUSER;
error = git_remote_push(_remote, &specs, &opts, pusher, "test push");
git__free(specs.strings);
if (expected_ret < 0) { if (expected_ret < 0) {
cl_git_fail_with(git_push_finish(push), expected_ret); cl_git_fail_with(expected_ret, error);
cl_assert_equal_i(0, git_push_unpack_ok(push));
} else { } else {
cl_git_pass(git_push_finish(push)); cl_git_pass(error);
cl_assert_equal_i(1, git_push_unpack_ok(push));
} }
if (check_progress_cb && !expected_ret) { if (check_progress_cb && expected_ret == 0) {
cl_assert(pack_progress_calls > 0); cl_assert(data->pack_progress_calls > 0);
cl_assert(transfer_progress_calls > 0); cl_assert(data->transfer_progress_calls > 0);
} }
do_verify_push_status(push, expected_statuses, expected_statuses_len); do_verify_push_status(data, expected_statuses, expected_statuses_len);
verify_refs(_remote, expected_refs, expected_refs_len); verify_refs(_remote, expected_refs, expected_refs_len);
cl_git_pass(git_push_update_tips(push, pusher, "test push"));
verify_tracking_branches(_remote, expected_refs, expected_refs_len); verify_tracking_branches(_remote, expected_refs, expected_refs_len);
if (check_update_tips_cb) if (check_update_tips_cb)
verify_update_tips_callback(_remote, expected_refs, expected_refs_len); verify_update_tips_callback(_remote, expected_refs, expected_refs_len);
git_push_free(push);
git_remote_disconnect(_remote);
git_signature_free(pusher); git_signature_free(pusher);
} }
......
...@@ -14,15 +14,31 @@ void updated_tip_free(updated_tip *t) ...@@ -14,15 +14,31 @@ void updated_tip_free(updated_tip *t)
git__free(t); git__free(t);
} }
void push_status_free(push_status *s)
{
git__free(s->ref);
git__free(s->msg);
git__free(s);
}
void record_callbacks_data_clear(record_callbacks_data *data) void record_callbacks_data_clear(record_callbacks_data *data)
{ {
size_t i; size_t i;
updated_tip *tip; updated_tip *tip;
push_status *status;
git_vector_foreach(&data->updated_tips, i, tip) git_vector_foreach(&data->updated_tips, i, tip)
updated_tip_free(tip); updated_tip_free(tip);
git_vector_free(&data->updated_tips); git_vector_free(&data->updated_tips);
git_vector_foreach(&data->statuses, i, status)
push_status_free(status);
git_vector_free(&data->statuses);
data->pack_progress_calls = 0;
data->transfer_progress_calls = 0;
} }
int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *data) int record_update_tips_cb(const char *refname, const git_oid *a, const git_oid *b, void *data)
......
...@@ -22,6 +22,9 @@ typedef struct { ...@@ -22,6 +22,9 @@ typedef struct {
typedef struct { typedef struct {
git_vector updated_tips; git_vector updated_tips;
git_vector statuses;
int pack_progress_calls;
int transfer_progress_calls;
} record_callbacks_data; } record_callbacks_data;
typedef struct { typedef struct {
...@@ -29,6 +32,15 @@ typedef struct { ...@@ -29,6 +32,15 @@ typedef struct {
const git_oid *oid; const git_oid *oid;
} expected_ref; } expected_ref;
/* the results of a push status. when used for expected values, msg may be NULL
* to indicate that it should not be matched. */
typedef struct {
char *ref;
int success;
char *msg;
} push_status;
void updated_tip_free(updated_tip *t); void updated_tip_free(updated_tip *t);
void record_callbacks_data_clear(record_callbacks_data *data); void record_callbacks_data_clear(record_callbacks_data *data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment