@@ -95,5 +95,70 @@ def test_normalize_gerrit_url_with_mixed_mappings(self, mock_load_config):
9595 )
9696
9797
98+ @patch ("gerrit_mcp_server.main.load_gerrit_config" )
99+ def test_normalize_gerrit_url_adds_a_prefix_for_http_basic (self , mock_load_config ):
100+ mock_load_config .return_value = {
101+ "gerrit_hosts" : [
102+ {
103+ "name" : "GerritHub" ,
104+ "external_url" : "https://review.gerrithub.io/" ,
105+ "authentication" : {"type" : "http_basic" , "username" : "u" , "auth_token" : "t" },
106+ }
107+ ]
108+ }
109+ gerrit_hosts = mock_load_config .return_value ["gerrit_hosts" ]
110+ self .assertEqual (
111+ _normalize_gerrit_url ("review.gerrithub.io" , gerrit_hosts ), "https://review.gerrithub.io/a"
112+ )
113+
114+ @patch ("gerrit_mcp_server.main.load_gerrit_config" )
115+ def test_normalize_gerrit_url_adds_a_prefix_for_git_cookies (self , mock_load_config ):
116+ mock_load_config .return_value = {
117+ "gerrit_hosts" : [
118+ {
119+ "name" : "Self-hosted" ,
120+ "external_url" : "https://gerrit.example.com/" ,
121+ "authentication" : {"type" : "git_cookies" , "gitcookies_path" : "~/.gitcookies" },
122+ }
123+ ]
124+ }
125+ gerrit_hosts = mock_load_config .return_value ["gerrit_hosts" ]
126+ self .assertEqual (
127+ _normalize_gerrit_url ("gerrit.example.com" , gerrit_hosts ), "https://gerrit.example.com/a"
128+ )
129+
130+ @patch ("gerrit_mcp_server.main.load_gerrit_config" )
131+ def test_normalize_gerrit_url_no_a_prefix_for_gob_curl (self , mock_load_config ):
132+ mock_load_config .return_value = {
133+ "gerrit_hosts" : [
134+ {
135+ "name" : "Google" ,
136+ "external_url" : "https://fuchsia-review.googlesource.com/" ,
137+ "authentication" : {"type" : "gob_curl" },
138+ }
139+ ]
140+ }
141+ gerrit_hosts = mock_load_config .return_value ["gerrit_hosts" ]
142+ self .assertEqual (
143+ _normalize_gerrit_url ("fuchsia-review.googlesource.com" , gerrit_hosts ),
144+ "https://fuchsia-review.googlesource.com" ,
145+ )
146+
147+ @patch ("gerrit_mcp_server.main.load_gerrit_config" )
148+ def test_normalize_gerrit_url_no_a_prefix_without_authentication (self , mock_load_config ):
149+ mock_load_config .return_value = {
150+ "gerrit_hosts" : [
151+ {
152+ "name" : "NoAuth" ,
153+ "external_url" : "https://noauth.gerrit.com/" ,
154+ }
155+ ]
156+ }
157+ gerrit_hosts = mock_load_config .return_value ["gerrit_hosts" ]
158+ self .assertEqual (
159+ _normalize_gerrit_url ("noauth.gerrit.com" , gerrit_hosts ), "https://noauth.gerrit.com"
160+ )
161+
162+
98163if __name__ == "__main__" :
99164 unittest .main ()
0 commit comments