summaryrefslogtreecommitdiff
path: root/tests-clar/network
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar/network')
-rw-r--r--tests-clar/network/createremotethenload.c33
-rw-r--r--tests-clar/network/remotelocal.c108
-rw-r--r--tests-clar/network/remotes.c50
3 files changed, 191 insertions, 0 deletions
diff --git a/tests-clar/network/createremotethenload.c b/tests-clar/network/createremotethenload.c
new file mode 100644
index 000000000..68ba9291e
--- /dev/null
+++ b/tests-clar/network/createremotethenload.c
@@ -0,0 +1,33 @@
+#include "clar_libgit2.h"
+
+static git_remote *_remote;
+static git_repository *_repo;
+static git_config *_config;
+static char url[] = "http://github.com/libgit2/libgit2.git";
+
+void test_network_createremotethenload__initialize(void)
+{
+ cl_fixture_sandbox("testrepo.git");
+
+ cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
+
+ cl_git_pass(git_repository_config(&_config, _repo));
+ cl_git_pass(git_config_set_string(_config, "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"));
+ cl_git_pass(git_config_set_string(_config, "remote.origin.url", url));
+ git_config_free(_config);
+
+ cl_git_pass(git_remote_load(&_remote, _repo, "origin"));
+}
+
+void test_network_createremotethenload__cleanup(void)
+{
+ git_remote_free(_remote);
+ git_repository_free(_repo);
+ cl_fixture_cleanup("testrepo.git");
+}
+
+void test_network_createremotethenload__parsing(void)
+{
+ cl_assert(!strcmp(git_remote_name(_remote), "origin"));
+ cl_assert(!strcmp(git_remote_url(_remote), url));
+}
diff --git a/tests-clar/network/remotelocal.c b/tests-clar/network/remotelocal.c
new file mode 100644
index 000000000..81af77756
--- /dev/null
+++ b/tests-clar/network/remotelocal.c
@@ -0,0 +1,108 @@
+#include "clar_libgit2.h"
+#include "transport.h"
+#include "buffer.h"
+#include "path.h"
+#include "posix.h"
+
+static git_repository *repo;
+static git_buf file_path_buf = GIT_BUF_INIT;
+static git_remote *remote;
+
+static void build_local_file_url(git_buf *out, const char *fixture)
+{
+ const char *in_buf;
+
+ git_buf path_buf = GIT_BUF_INIT;
+
+ cl_git_pass(git_path_prettify_dir(&path_buf, fixture, NULL));
+ cl_git_pass(git_buf_puts(out, "file://"));
+
+#ifdef _MSC_VER
+ /*
+ * A FILE uri matches the following format: file://[host]/path
+ * where "host" can be empty and "path" is an absolute path to the resource.
+ *
+ * In this test, no hostname is used, but we have to ensure the leading triple slashes:
+ *
+ * *nix: file:///usr/home/...
+ * Windows: file:///C:/Users/...
+ */
+ cl_git_pass(git_buf_putc(out, '/'));
+#endif
+
+ in_buf = git_buf_cstr(&path_buf);
+
+ /*
+ * A very hacky Url encoding that only takes care of escaping the spaces
+ */
+ while (*in_buf) {
+ if (*in_buf == ' ')
+ cl_git_pass(git_buf_puts(out, "%20"));
+ else
+ cl_git_pass(git_buf_putc(out, *in_buf));
+
+ in_buf++;
+ }
+
+ git_buf_free(&path_buf);
+}
+
+void test_network_remotelocal__initialize(void)
+{
+ cl_git_pass(git_repository_init(&repo, "remotelocal/", 0));
+ cl_assert(repo != NULL);
+}
+
+void test_network_remotelocal__cleanup(void)
+{
+ git_remote_free(remote);
+ git_buf_free(&file_path_buf);
+ git_repository_free(repo);
+ cl_fixture_cleanup("remotelocal");
+}
+
+static int count_ref__cb(git_remote_head *head, void *payload)
+{
+ int *count = (int *)payload;
+
+ (void)head;
+ (*count)++;
+
+ return GIT_SUCCESS;
+}
+
+static void connect_to_local_repository(const char *local_repository)
+{
+ build_local_file_url(&file_path_buf, local_repository);
+
+ cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL));
+ cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
+
+}
+
+void test_network_remotelocal__retrieve_advertised_references(void)
+{
+ int how_many_refs = 0;
+
+ connect_to_local_repository(cl_fixture("testrepo.git"));
+
+ cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
+
+ cl_assert(how_many_refs == 12); /* 1 HEAD + 9 refs + 2 peeled tags */
+}
+
+void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void)
+{
+ int how_many_refs = 0;
+
+ cl_fixture_sandbox("testrepo.git");
+ cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git"));
+
+ connect_to_local_repository("spaced testrepo.git");
+
+ cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs));
+
+ cl_assert(how_many_refs == 12); /* 1 HEAD */
+
+ cl_fixture_cleanup("spaced testrepo.git");
+}
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
new file mode 100644
index 000000000..2abaccb07
--- /dev/null
+++ b/tests-clar/network/remotes.c
@@ -0,0 +1,50 @@
+#include "clar_libgit2.h"
+
+static git_remote *_remote;
+static git_repository *_repo;
+static const git_refspec *_refspec;
+
+void test_network_remotes__initialize(void)
+{
+ cl_fixture_sandbox("testrepo.git");
+
+ cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
+ cl_git_pass(git_remote_load(&_remote, _repo, "test"));
+
+ _refspec = git_remote_fetchspec(_remote);
+ cl_assert(_refspec != NULL);
+}
+
+void test_network_remotes__cleanup(void)
+{
+ git_remote_free(_remote);
+ git_repository_free(_repo);
+ cl_fixture_cleanup("testrepo.git");
+}
+
+void test_network_remotes__parsing(void)
+{
+ cl_assert(!strcmp(git_remote_name(_remote), "test"));
+ cl_assert(!strcmp(git_remote_url(_remote), "git://github.com/libgit2/libgit2"));
+}
+
+void test_network_remotes__refspec_parsing(void)
+{
+ cl_assert(!strcmp(git_refspec_src(_refspec), "refs/heads/*"));
+ cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/remotes/test/*"));
+}
+
+void test_network_remotes__fnmatch(void)
+{
+ cl_git_pass(git_refspec_src_match(_refspec, "refs/heads/master"));
+ cl_git_pass(git_refspec_src_match(_refspec, "refs/heads/multi/level/branch"));
+}
+
+void test_network_remotes__transform(void)
+{
+ char ref[1024];
+
+ memset(ref, 0x0, sizeof(ref));
+ cl_git_pass(git_refspec_transform(ref, sizeof(ref), _refspec, "refs/heads/master"));
+ cl_assert(!strcmp(ref, "refs/remotes/test/master"));
+}