Skip to content

Commit 10fa2dd

Browse files
committed
tests: consolidate all remote creation tests in one test suite
1 parent 798be87 commit 10fa2dd

File tree

2 files changed

+70
-62
lines changed

2 files changed

+70
-62
lines changed

tests/network/remote/remotes.c

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -312,30 +312,6 @@ void test_network_remote_remotes__add(void)
312312
cl_assert_equal_s(git_remote_url(_remote), "http://github.com/libgit2/libgit2");
313313
}
314314

315-
void test_network_remote_remotes__cannot_add_a_nameless_remote(void)
316-
{
317-
git_remote *remote;
318-
319-
cl_assert_equal_i(
320-
GIT_EINVALIDSPEC,
321-
git_remote_create(&remote, _repo, NULL, "git://github.com/libgit2/libgit2"));
322-
}
323-
324-
void test_network_remote_remotes__cannot_add_a_remote_with_an_invalid_name(void)
325-
{
326-
git_remote *remote = NULL;
327-
328-
cl_assert_equal_i(
329-
GIT_EINVALIDSPEC,
330-
git_remote_create(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2"));
331-
cl_assert_equal_p(remote, NULL);
332-
333-
cl_assert_equal_i(
334-
GIT_EINVALIDSPEC,
335-
git_remote_create(&remote, _repo, "", "git://github.com/libgit2/libgit2"));
336-
cl_assert_equal_p(remote, NULL);
337-
}
338-
339315
void test_network_remote_remotes__tagopt(void)
340316
{
341317
const char *name = git_remote_name(_remote);
@@ -389,41 +365,6 @@ void test_network_remote_remotes__returns_ENOTFOUND_when_neither_url_nor_pushurl
389365
git_remote_lookup(&remote, _repo, "no-remote-url"), GIT_ENOTFOUND);
390366
}
391367

392-
void assert_cannot_create_remote(const char *name, int expected_error)
393-
{
394-
git_remote *remote = NULL;
395-
396-
cl_git_fail_with(
397-
git_remote_create(&remote, _repo, name, "git://github.com/libgit2/libgit2"),
398-
expected_error);
399-
400-
cl_assert_equal_p(remote, NULL);
401-
}
402-
403-
void test_network_remote_remotes__cannot_create_a_remote_which_name_conflicts_with_an_existing_remote(void)
404-
{
405-
assert_cannot_create_remote("test", GIT_EEXISTS);
406-
}
407-
408-
void test_network_remote_remotes__cannot_create_a_remote_which_name_is_invalid(void)
409-
{
410-
assert_cannot_create_remote("/", GIT_EINVALIDSPEC);
411-
assert_cannot_create_remote("//", GIT_EINVALIDSPEC);
412-
assert_cannot_create_remote(".lock", GIT_EINVALIDSPEC);
413-
assert_cannot_create_remote("a.lock", GIT_EINVALIDSPEC);
414-
}
415-
416-
void test_network_remote_remote__git_remote_create_with_fetchspec(void)
417-
{
418-
git_remote *remote;
419-
git_strarray array;
420-
421-
cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "test-new", "git://github.com/libgit2/libgit2", "+refs/*:refs/*"));
422-
git_remote_get_fetch_refspecs(&array, remote);
423-
cl_assert_equal_s("+refs/*:refs/*", array.strings[0]);
424-
git_remote_free(remote);
425-
}
426-
427368
static const char *fetch_refspecs[] = {
428369
"+refs/heads/*:refs/remotes/origin/*",
429370
"refs/tags/*:refs/tags/*",

tests/remote/create.c

Lines changed: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@
22

33
static git_repository *_repo;
44
static git_config *_config;
5-
static char url[] = "http://github.com/libgit2/libgit2.git";
5+
6+
#define TEST_URL "http://github.com/libgit2/libgit2.git"
7+
8+
#define cl_git_assert_cannot_create_remote(expected, creation_expr) \
9+
do { \
10+
git_remote *r = NULL; \
11+
int res = ((creation_expr)); \
12+
cl_git_fail_with(expected, res); \
13+
cl_assert_equal_p(r, NULL); \
14+
} while (0);
15+
616

717
void test_remote_create__initialize(void)
818
{
@@ -27,11 +37,68 @@ void test_remote_create__manual(void)
2737
{
2838
git_remote *remote;
2939
cl_git_pass(git_config_set_string(_config, "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"));
30-
cl_git_pass(git_config_set_string(_config, "remote.origin.url", url));
40+
cl_git_pass(git_config_set_string(_config, "remote.origin.url", TEST_URL));
3141

3242
cl_git_pass(git_remote_lookup(&remote, _repo, "origin"));
3343
cl_assert_equal_s(git_remote_name(remote), "origin");
34-
cl_assert_equal_s(git_remote_url(remote), url);
44+
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
45+
46+
git_remote_free(remote);
47+
}
48+
49+
void test_remote_create__named(void)
50+
{
51+
git_remote *remote;
52+
git_config *cfg;
53+
const char *cfg_val;
54+
cl_git_pass(git_remote_create(&remote, _repo, "valid-name", TEST_URL));
55+
56+
cl_assert_equal_s(git_remote_name(remote), "valid-name");
57+
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
58+
59+
cl_git_pass(git_repository_config_snapshot(&cfg, _repo));
60+
61+
cl_git_pass(git_config_get_string(&cfg_val, cfg, "remote.valid-name.fetch"));
62+
cl_assert_equal_s(cfg_val, "+refs/heads/*:refs/remotes/valid-name/*");
63+
64+
cl_git_pass(git_config_get_string(&cfg_val, cfg, "remote.valid-name.url"));
65+
cl_assert_equal_s(cfg_val, TEST_URL);
66+
67+
git_config_free(cfg);
68+
git_remote_free(remote);
69+
}
70+
71+
void test_remote_create__named_fail_on_invalid_name(void)
72+
{
73+
cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, git_remote_create(&r, _repo, NULL, TEST_URL));
74+
cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, git_remote_create(&r, _repo, "Inv@{id", TEST_URL));
75+
cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, git_remote_create(&r, _repo, "", TEST_URL));
76+
cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, git_remote_create(&r, _repo, "/", TEST_URL));
77+
cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, git_remote_create(&r, _repo, "//", TEST_URL));
78+
cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, git_remote_create(&r, _repo, ".lock", TEST_URL));
79+
cl_git_assert_cannot_create_remote(GIT_EINVALIDSPEC, git_remote_create(&r, _repo, "a.lock", TEST_URL));
80+
}
81+
82+
void test_remote_create__named_fail_on_invalid_url(void)
83+
{
84+
cl_git_assert_cannot_create_remote(GIT_ERROR, git_remote_create(&r, _repo, "bad-url", ""));
85+
}
86+
87+
void test_remote_create__named_fail_on_conflicting_name(void)
88+
{
89+
cl_git_assert_cannot_create_remote(GIT_EEXISTS, git_remote_create(&r, _repo, "test", TEST_URL));
90+
}
91+
92+
void test_remote_create__with_fetchspec(void)
93+
{
94+
git_remote *remote;
95+
git_strarray array;
96+
97+
cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "test-new", "git://github.com/libgit2/libgit2", "+refs/*:refs/*"));
98+
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
99+
cl_assert_equal_s("+refs/*:refs/*", array.strings[0]);
100+
cl_assert_equal_i(1, array.count);
35101

102+
git_strarray_free(&array);
36103
git_remote_free(remote);
37104
}

0 commit comments

Comments
 (0)