summaryrefslogtreecommitdiff
path: root/tests/network
diff options
context:
space:
mode:
Diffstat (limited to 'tests/network')
-rw-r--r--tests/network/fetchlocal.c35
-rw-r--r--tests/network/refspecs.c23
-rw-r--r--tests/network/remote/remotes.c30
-rw-r--r--tests/network/urlparse.c18
4 files changed, 70 insertions, 36 deletions
diff --git a/tests/network/fetchlocal.c b/tests/network/fetchlocal.c
index 0d23bef48..8809f427d 100644
--- a/tests/network/fetchlocal.c
+++ b/tests/network/fetchlocal.c
@@ -87,28 +87,43 @@ void test_network_fetchlocal__partial(void)
git_remote_free(origin);
}
-void test_network_fetchlocal__clone_into_mirror(void)
+static int remote_mirror_cb(git_remote **out, git_repository *repo,
+ const char *name, const char *url, void *payload)
{
- git_buf path = GIT_BUF_INIT;
- git_repository *repo;
+ int error;
git_remote *remote;
- git_reference *head;
- cl_git_pass(git_repository_init(&repo, "./foo.git", true));
- cl_git_pass(git_remote_create(&remote, repo, "origin", cl_git_fixture_url("testrepo.git")));
+ GIT_UNUSED(payload);
+
+ if ((error = git_remote_create(&remote, repo, name, url)) < 0)
+ return error;
git_remote_clear_refspecs(remote);
- cl_git_pass(git_remote_add_fetch(remote, "+refs/*:refs/*"));
- cl_git_pass(git_clone_into(repo, remote, NULL, NULL, NULL));
+ if ((error = git_remote_add_fetch(remote, "+refs/*:refs/*")) < 0) {
+ git_remote_free(remote);
+ return error;
+ }
+
+ *out = remote;
+ return 0;
+}
+
+void test_network_fetchlocal__clone_into_mirror(void)
+{
+ git_clone_options opts = GIT_CLONE_OPTIONS_INIT;
+ git_repository *repo;
+ git_reference *head;
+
+ opts.bare = true;
+ opts.remote_cb = remote_mirror_cb;
+ cl_git_pass(git_clone(&repo, cl_git_fixture_url("testrepo.git"), "./foo.git", &opts));
cl_git_pass(git_reference_lookup(&head, repo, "HEAD"));
cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head));
cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
- git_remote_free(remote);
git_reference_free(head);
git_repository_free(repo);
- git_buf_free(&path);
cl_fixture_cleanup("./foo.git");
}
diff --git a/tests/network/refspecs.c b/tests/network/refspecs.c
index 676a1fa99..aa9b36e58 100644
--- a/tests/network/refspecs.c
+++ b/tests/network/refspecs.c
@@ -84,4 +84,27 @@ void test_network_refspecs__parsing(void)
assert_refspec(GIT_DIRECTION_FETCH, "master", true);
assert_refspec(GIT_DIRECTION_PUSH, "master", true);
+
+ assert_refspec(GIT_DIRECTION_FETCH, "refs/pull/*/head:refs/remotes/origin/pr/*", true);
+}
+
+void assert_transform(const char *refspec, const char *name, const char *result)
+{
+ git_refspec spec;
+ git_buf buf = GIT_BUF_INIT;
+
+ git_refspec__parse(&spec, refspec, true);
+ cl_git_pass(git_refspec_transform(&buf, &spec, name));
+ cl_assert_equal_s(result, buf.ptr);
+
+ git_buf_free(&buf);
+ git_refspec__free(&spec);
+}
+
+void test_network_refspecs__transform_mid_star(void)
+{
+ assert_transform("refs/pull/*/head:refs/remotes/origin/pr/*", "refs/pull/23/head", "refs/remotes/origin/pr/23");
+ assert_transform("refs/heads/*:refs/remotes/origin/*", "refs/heads/master", "refs/remotes/origin/master");
+ assert_transform("refs/heads/*:refs/heads/*", "refs/heads/master", "refs/heads/master");
+ assert_transform("refs/*:refs/*", "refs/heads/master", "refs/heads/master");
}
diff --git a/tests/network/remote/remotes.c b/tests/network/remote/remotes.c
index 333b52a5b..21c57119a 100644
--- a/tests/network/remote/remotes.c
+++ b/tests/network/remote/remotes.c
@@ -72,18 +72,17 @@ void test_network_remote_remotes__error_when_not_found(void)
void test_network_remote_remotes__error_when_no_push_available(void)
{
git_remote *r;
- git_transport *t;
git_push *p;
cl_git_pass(git_remote_create_anonymous(&r, _repo, cl_fixture("testrepo.git"), NULL));
- cl_git_pass(git_transport_local(&t,r,NULL));
+ cl_git_pass(git_remote_set_transport(r, git_transport_local, NULL));
+
+ cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH));
/* Make sure that push is really not available */
- t->push = NULL;
- cl_git_pass(git_remote_set_transport(r, t));
+ r->transport->push = NULL;
- cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH));
cl_git_pass(git_push_new(&p, r));
cl_git_pass(git_push_add_refspec(p, "refs/heads/master"));
cl_git_fail_with(git_push_finish(p), GIT_ERROR);
@@ -438,27 +437,6 @@ void test_network_remote_remotes__returns_ENOTFOUND_when_neither_url_nor_pushurl
git_remote_load(&remote, _repo, "no-remote-url"), GIT_ENOTFOUND);
}
-void test_network_remote_remotes__check_structure_version(void)
-{
- git_transport transport = GIT_TRANSPORT_INIT;
- const git_error *err;
-
- git_remote_free(_remote);
- _remote = NULL;
- cl_git_pass(git_remote_create_anonymous(&_remote, _repo, "test-protocol://localhost", NULL));
-
- transport.version = 0;
- cl_git_fail(git_remote_set_transport(_remote, &transport));
- err = giterr_last();
- cl_assert_equal_i(GITERR_INVALID, err->klass);
-
- giterr_clear();
- transport.version = 1024;
- cl_git_fail(git_remote_set_transport(_remote, &transport));
- err = giterr_last();
- cl_assert_equal_i(GITERR_INVALID, err->klass);
-}
-
void assert_cannot_create_remote(const char *name, int expected_error)
{
git_remote *remote = NULL;
diff --git a/tests/network/urlparse.c b/tests/network/urlparse.c
index 2a9c2f69f..b3ac8ae60 100644
--- a/tests/network/urlparse.c
+++ b/tests/network/urlparse.c
@@ -33,6 +33,24 @@ void test_network_urlparse__trivial(void)
cl_assert_equal_p(pass, NULL);
}
+void test_network_urlparse__root(void)
+{
+ cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,
+ "http://example.com/", "8080"));
+ cl_assert_equal_s(host, "example.com");
+ cl_assert_equal_s(port, "8080");
+ cl_assert_equal_s(path, "/");
+ cl_assert_equal_p(user, NULL);
+ cl_assert_equal_p(pass, NULL);
+}
+
+void test_network_urlparse__just_hostname(void)
+{
+ cl_git_fail_with(GIT_EINVALIDSPEC,
+ gitno_extract_url_parts(&host, &port, &path, &user, &pass,
+ "http://example.com", "8080"));
+}
+
void test_network_urlparse__encoded_password(void)
{
cl_git_pass(gitno_extract_url_parts(&host, &port, &path, &user, &pass,