nickva commented on code in PR #4761:
URL: https://github.com/apache/couchdb/pull/4761#discussion_r1326338963


##########
src/couch_replicator/src/couch_replicator_utils.erl:
##########
@@ -682,4 +686,61 @@ auth_props(User, Pass) when is_list(User), is_list(Pass) ->
             ]}}
     ].
 
+http_log_setup() ->
+    Ctx = test_util:start_couch(),
+    config:set("replicator", "valid_endpoint_protocols_log", "true", false),
+    meck:new(couch_log, [passthrough]),
+    Ctx.
+
+http_log_teardown(Ctx) ->
+    meck:unload(),
+    config:delete("replicator", "valid_endpoint_protocols_log", false),
+    test_util:stop_couch(Ctx).
+
+valid_protocol_log_test_() ->
+    {
+        foreach,
+        fun http_log_setup/0,
+        fun http_log_teardown/1,
+        [
+            ?TDEF_FE(t_warn_on_http_urls),
+            ?TDEF_FE(t_dont_warn_on_https_urls),
+            ?TDEF_FE(t_dont_warn_if_disabled),
+            ?TDEF_FE(t_allow_canceling_transient_jobs)
+        ]
+    }.
+
+t_warn_on_http_urls(_) ->
+    Rep = #rep{
+        source = #httpdb{url = "http://foo.local"},
+        target = #httpdb{url = "http://127.0.0.2"}
+    },
+    meck:reset(couch_log),
+    ?assertEqual(ok, valid_endpoint_protocols_log(Rep)),
+    ?assertEqual(2, meck:num_calls(couch_log, warning, 2)).
+
+t_dont_warn_on_https_urls(_) ->
+    Rep = #rep{
+        source = #httpdb{url = "https://foo.local"},
+        target = #httpdb{url = "https://127.0.0.2"}
+    },
+    meck:reset(couch_log),
+    ?assertEqual(ok, valid_endpoint_protocols_log(Rep)),
+    ?assertEqual(0, meck:num_calls(couch_log, warning, 2)).
+
+t_dont_warn_if_disabled(_) ->
+    config:set("replicator", "valid_endpoint_protocols_log", "false", false),
+    Rep = #rep{
+        source = #httpdb{url = "http://foo.local"},
+        target = #httpdb{url = "http://127.0.0.2"}
+    },
+    meck:reset(couch_log),
+    ?assertEqual(ok, valid_endpoint_protocols_log(Rep)),
+    ?assertEqual(0, meck:num_calls(couch_log, warning, 2)).
+
+t_allow_canceling_transient_jobs(_) ->
+    meck:reset(couch_log),
+    ?assertEqual(ok, valid_endpoint_protocols_log(#rep{})),

Review Comment:
   Good idea. Added a comment.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@couchdb.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to