]> git.proxmox.com Git - libgit2.git/blob - tests/remote/insteadof.c
c39df4be7f2b2d825379eb8ac2751475eec51193
[libgit2.git] / tests / remote / insteadof.c
1 #include "clar_libgit2.h"
2 #include "remote.h"
3 #include "repository.h"
4
5 #define REPO_PATH "testrepo2/.gitted"
6 #define REMOTE_ORIGIN "origin"
7 #define REMOTE_INSTEADOF_URL_FETCH "insteadof-url-fetch"
8 #define REMOTE_INSTEADOF_URL_PUSH "insteadof-url-push"
9 #define REMOTE_INSTEADOF_URL_BOTH "insteadof-url-both"
10 #define REMOTE_INSTEADOF_PUSHURL_FETCH "insteadof-pushurl-fetch"
11 #define REMOTE_INSTEADOF_PUSHURL_PUSH "insteadof-pushurl-push"
12 #define REMOTE_INSTEADOF_PUSHURL_BOTH "insteadof-pushurl-both"
13
14 static git_repository *g_repo;
15 static git_remote *g_remote;
16
17 void test_remote_insteadof__initialize(void)
18 {
19 g_repo = NULL;
20 g_remote = NULL;
21 }
22
23 void test_remote_insteadof__cleanup(void)
24 {
25 git_repository_free(g_repo);
26 git_remote_free(g_remote);
27 }
28
29 void test_remote_insteadof__not_applicable(void)
30 {
31 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
32 cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_ORIGIN));
33
34 cl_assert_equal_s(
35 git_remote_url(g_remote),
36 "https://github.com/libgit2/false.git");
37 cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
38 }
39
40 void test_remote_insteadof__url_insteadof_fetch(void)
41 {
42 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
43 cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_FETCH));
44
45 cl_assert_equal_s(
46 git_remote_url(g_remote),
47 "http://github.com/url/fetch/libgit2");
48 cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
49 }
50
51 void test_remote_insteadof__url_insteadof_push(void)
52 {
53 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
54 cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_PUSH));
55
56 cl_assert_equal_s(
57 git_remote_url(g_remote),
58 "http://example.com/url/push/libgit2");
59 cl_assert_equal_s(
60 git_remote_pushurl(g_remote),
61 "git@github.com:url/push/libgit2");
62 }
63
64 void test_remote_insteadof__url_insteadof_both(void)
65 {
66 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
67 cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_URL_BOTH));
68
69 cl_assert_equal_s(
70 git_remote_url(g_remote),
71 "http://github.com/url/both/libgit2");
72 cl_assert_equal_s(
73 git_remote_pushurl(g_remote),
74 "git@github.com:url/both/libgit2");
75 }
76
77 void test_remote_insteadof__pushurl_insteadof_fetch(void)
78 {
79 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
80 cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_FETCH));
81
82 cl_assert_equal_s(
83 git_remote_url(g_remote),
84 "http://github.com/url/fetch/libgit2");
85 cl_assert_equal_s(
86 git_remote_pushurl(g_remote),
87 "http://github.com/url/fetch/libgit2-push");
88 }
89
90 void test_remote_insteadof__pushurl_insteadof_push(void)
91 {
92 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
93 cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_PUSH));
94
95 cl_assert_equal_s(
96 git_remote_url(g_remote),
97 "http://example.com/url/push/libgit2");
98 cl_assert_equal_s(
99 git_remote_pushurl(g_remote),
100 "http://example.com/url/push/libgit2-push");
101 }
102
103 void test_remote_insteadof__pushurl_insteadof_both(void)
104 {
105 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
106 cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_INSTEADOF_PUSHURL_BOTH));
107
108 cl_assert_equal_s(
109 git_remote_url(g_remote),
110 "http://github.com/url/both/libgit2");
111 cl_assert_equal_s(
112 git_remote_pushurl(g_remote),
113 "http://github.com/url/both/libgit2-push");
114 }
115
116 void test_remote_insteadof__anonymous_remote_fetch(void)
117 {
118 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
119 cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
120 "http://example.com/url/fetch/libgit2"));
121
122 cl_assert_equal_s(
123 git_remote_url(g_remote),
124 "http://github.com/url/fetch/libgit2");
125 cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
126 }
127
128 void test_remote_insteadof__anonymous_remote_push(void)
129 {
130 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
131 cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
132 "http://example.com/url/push/libgit2"));
133
134 cl_assert_equal_s(
135 git_remote_url(g_remote),
136 "http://example.com/url/push/libgit2");
137 cl_assert_equal_s(
138 git_remote_pushurl(g_remote),
139 "git@github.com:url/push/libgit2");
140 }
141
142 void test_remote_insteadof__anonymous_remote_both(void)
143 {
144 cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
145 cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
146 "http://example.com/url/both/libgit2"));
147
148 cl_assert_equal_s(
149 git_remote_url(g_remote),
150 "http://github.com/url/both/libgit2");
151 cl_assert_equal_s(
152 git_remote_pushurl(g_remote),
153 "git@github.com:url/both/libgit2");
154 }