summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2014-05-27 17:51:25 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2014-05-27 17:51:25 +0200
commit4625003149d02227f981b53101c7e6be12226382 (patch)
treeac1a86f48c69d4da0ec14adc4860f0be7ab422ec /tests
parent16b20526e1580f50b29f0dae87a30ebefe0a3c89 (diff)
downloadlibgit2-cmn/server.tar.gz
server: handle negotiation linescmn/server
A bit of scaffolding for handling the lines from the client telling us about its commits.
Diffstat (limited to 'tests')
-rw-r--r--tests/network/protocol/negotiation.c40
-rw-r--r--tests/network/server.c33
2 files changed, 73 insertions, 0 deletions
diff --git a/tests/network/protocol/negotiation.c b/tests/network/protocol/negotiation.c
new file mode 100644
index 000000000..0fa76a257
--- /dev/null
+++ b/tests/network/protocol/negotiation.c
@@ -0,0 +1,40 @@
+#include "clar_libgit2.h"
+#include "transports/smart.h"
+
+static git_pkt *pkt;
+
+void test_network_protocol_negotiation__cleanup(void)
+{
+ git_pkt_free(pkt);
+ pkt = NULL;
+}
+
+void test_network_protocol_negotiation__have(void)
+{
+ const char buf[] = "0032have 7e47fe2bd8d01d481f44d7af0531bd93d3b21c01\n";
+ const char *rest;
+ git_oid id;
+ git_pkt_have_want *ppkt;
+
+ git_oid_fromstr(&id, "7e47fe2bd8d01d481f44d7af0531bd93d3b21c01");
+
+ cl_git_pass(git_pkt_parse_line(&pkt, buf, &rest, sizeof(buf)));
+ cl_assert_equal_i(GIT_PKT_HAVE, pkt->type);
+ ppkt = (git_pkt_have_want *) pkt;
+ cl_assert(!git_oid_cmp(&id, &ppkt->id));
+}
+
+void test_network_protocol_negotiation__want(void)
+{
+ const char buf[] = "0032want 7e47fe2bd8d01d481f44d7af0531bd93d3b21c01\n";
+ const char *rest;
+ git_oid id;
+ git_pkt_have_want *ppkt;
+
+ git_oid_fromstr(&id, "7e47fe2bd8d01d481f44d7af0531bd93d3b21c01");
+
+ cl_git_pass(git_pkt_parse_line(&pkt, buf, &rest, sizeof(buf)));
+ cl_assert_equal_i(GIT_PKT_WANT, pkt->type);
+ ppkt = (git_pkt_have_want *) pkt;
+ cl_assert(!git_oid_cmp(&id, &ppkt->id));
+}
diff --git a/tests/network/server.c b/tests/network/server.c
index 41319552d..4fc81cb23 100644
--- a/tests/network/server.c
+++ b/tests/network/server.c
@@ -81,3 +81,36 @@ void test_network_server__upload_pack_ls(void)
git_buf_free(&listing);
}
+
+void test_network_server__want(void)
+{
+ const char buf[] = "0032want 7e47fe2bd8d01d481f44d7af0531bd93d3b21c01\n";
+ const char *rest;
+
+ cl_git_pass(git_pkt_parse_line(&g_pkt, buf, &rest, sizeof(buf)));
+ cl_git_pass(git_server_new(&g_server, g_repo, 0));
+ cl_git_pass(git_server__negotiation(g_server, g_pkt));
+ cl_assert_equal_i(1, git_array_size(g_server->wants));
+}
+
+void test_network_server__have_no_common(void)
+{
+ const char buf[] = "0032have 7e47fe2bd8d01d481f44d7af0531bd93d3b21c01\n";
+ const char *rest;
+
+ cl_git_pass(git_pkt_parse_line(&g_pkt, buf, &rest, sizeof(buf)));
+ cl_git_pass(git_server_new(&g_server, g_repo, 0));
+ cl_git_pass(git_server__negotiation(g_server, g_pkt));
+ cl_assert_equal_i(0, git_array_size(g_server->common));
+}
+
+void test_network_server__have_common(void)
+{
+ const char buf[] = "0032have a65fedf39aefe402d3bb6e24df4d4f5fe4547750\n";
+ const char *rest;
+
+ cl_git_pass(git_pkt_parse_line(&g_pkt, buf, &rest, sizeof(buf)));
+ cl_git_pass(git_server_new(&g_server, g_repo, 0));
+ cl_git_pass(git_server__negotiation(g_server, g_pkt));
+ cl_assert_equal_i(1, git_array_size(g_server->common));
+}