|
1 | 1 | #include "clar_libgit2.h" |
2 | | -#include "remote.h" |
| 2 | +#include "futils.h" |
3 | 3 | #include "net.h" |
| 4 | +#include "remote.h" |
4 | 5 |
|
5 | 6 | static git_repository *repo; |
6 | 7 | static git_net_url url = GIT_NET_URL_INIT; |
@@ -105,6 +106,45 @@ void test_remote_httpproxy__config_empty_overrides(void) |
105 | 106 | assert_config_match("remote.lg2.proxy", ""); |
106 | 107 | } |
107 | 108 |
|
| 109 | +void assert_global_config_match(const char *config, const char *expected) |
| 110 | +{ |
| 111 | + git_remote *remote; |
| 112 | + char *proxy; |
| 113 | + git_config* cfg; |
| 114 | + |
| 115 | + if (config) { |
| 116 | + cl_git_pass(git_config_open_default(&cfg)); |
| 117 | + git_config_set_string(cfg, config, expected); |
| 118 | + git_config_free(cfg); |
| 119 | + } |
| 120 | + |
| 121 | + cl_git_pass(git_remote_create_detached(&remote, "https://github.com/libgit2/libgit2")); |
| 122 | + cl_git_pass(git_remote__http_proxy(&proxy, remote, &url)); |
| 123 | + |
| 124 | + if (expected) |
| 125 | + cl_assert_equal_s(proxy, expected); |
| 126 | + else |
| 127 | + cl_assert_equal_p(proxy, expected); |
| 128 | + |
| 129 | + git_remote_free(remote); |
| 130 | + git__free(proxy); |
| 131 | +} |
| 132 | + |
| 133 | +void test_remote_httpproxy__config_overrides_detached_remote(void) |
| 134 | +{ |
| 135 | + cl_fake_home(); |
| 136 | + |
| 137 | + assert_global_config_match(NULL, NULL); |
| 138 | + assert_global_config_match("http.proxy", "http://localhost:1/"); |
| 139 | + assert_global_config_match("http.https://github.com.proxy", "http://localhost:2/"); |
| 140 | + assert_global_config_match("http.https://github.com/.proxy", "http://localhost:3/"); |
| 141 | + assert_global_config_match("http.https://github.com/libgit2.proxy", "http://localhost:4/"); |
| 142 | + assert_global_config_match("http.https://github.com/libgit2/.proxy", "http://localhost:5/"); |
| 143 | + assert_global_config_match("http.https://github.com/libgit2/libgit2.proxy", "http://localhost:6/"); |
| 144 | + |
| 145 | + cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES)); |
| 146 | +} |
| 147 | + |
108 | 148 | void test_remote_httpproxy__env(void) |
109 | 149 | { |
110 | 150 | orig_http_proxy = cl_getenv("HTTP_PROXY"); |
|
0 commit comments