nickva commented on a change in pull request #3567:
URL: https://github.com/apache/couchdb/pull/3567#discussion_r633704495



##########
File path: src/chttpd/test/eunit/chttpd_util_test.erl
##########
@@ -0,0 +1,94 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(chttpd_util_test).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include("chttpd_test.hrl").
+
+setup() -> ok.
+
+teardown(_) -> ok.
+
+chttpd_util_config_test_() ->
+       {
+               "chttpd util config tests",
+               {
+                       setup,
+                       fun test_util:start_couch/0,
+                       fun test_util:stop_couch/1,
+                       {
+                               foreach,
+                               fun setup/0,
+                               fun teardown/1,
+                               [
+                                       
?TDEF_FE(get_chttpd_config_with_undefined_option),
+                                       
?TDEF_FE(get_chttpd_config_with_httpd_option),
+                                       
?TDEF_FE(get_chttpd_config_with_chttpd_option),
+                                       
?TDEF_FE(get_chttpd_config_with_chttpd_option_which_moved_from_httpd),
+                                       
?TDEF_FE(get_chttpd_auth_config_with_undefined_option),
+                                       
?TDEF_FE(get_chttpd_auth_config_with_couch_httpd_auth_option),
+                                       
?TDEF_FE(get_chttpd_auth_config_with_chttpd_auth_option_which_moved_from_couch_httpd_auth)
+                               ]
+                       }
+               }
+       }.
+
+get_chttpd_config_with_undefined_option(_) ->
+       ?assertEqual(undefined, 
chttpd_util:get_chttpd_config(undefined_option)),
+       ?assertEqual(default, chttpd_util:get_chttpd_config(undefined_option, 
default)),
+       ?assertEqual(123, chttpd_util:get_chttpd_config(undefined_option, 123)),
+       ?assertEqual(0.2, chttpd_util:get_chttpd_config(undefined_option, 0.2)),
+       ?assert(chttpd_util:get_chttpd_config(undefined_option, true)),
+       ?assertNot(chttpd_util:get_chttpd_config(undefined_option, false)),
+       ?assertEqual("abc", chttpd_util:get_chttpd_config(undefined_option, 
"abc")),
+       ?assertEqual("", chttpd_util:get_chttpd_config(undefined_option, "")).
+
+get_chttpd_config_with_httpd_option(_) ->
+       ?assertEqual("0", chttpd_util:get_chttpd_config(port)),
+       ?assertEqual("127.0.0.1", chttpd_util:get_chttpd_config(bind_address)),
+       ?assertEqual("0", chttpd_util:get_chttpd_config(port, "8080")),
+       ?assertEqual("127.0.0.1", chttpd_util:get_chttpd_config(bind_address, 
"255.255.255.255")).
+
+get_chttpd_config_with_chttpd_option(_) ->
+       ?assertEqual("0", chttpd_util:get_chttpd_config(port)),
+       ?assertEqual("127.0.0.1", chttpd_util:get_chttpd_config(bind_address)),
+       ?assertEqual("100", 
chttpd_util:get_chttpd_config(max_db_number_for_dbs_info_req)),
+       ?assertEqual("0", chttpd_util:get_chttpd_config(port, "8080")),
+       ?assertEqual("127.0.0.1", chttpd_util:get_chttpd_config(bind_address, 
"127.0.0.2")),
+       ?assertEqual("100", 
chttpd_util:get_chttpd_config(max_db_number_for_dbs_info_req, "0")).
+
+get_chttpd_config_with_chttpd_option_which_moved_from_httpd(_) ->
+       ?assertEqual("4294967296", 
chttpd_util:get_chttpd_config(max_http_request_size)),
+       ?assertEqual("4294967296", 
chttpd_util:get_chttpd_config(max_http_request_size, "0")),
+       ?assertEqual(undefined, chttpd_util:get_chttpd_config(max_uri_length)),
+       ?assertEqual(6000, chttpd_util:get_chttpd_config(max_uri_length, 6000)),
+       ?assertEqual("X-Forwarded-Host", 
chttpd_util:get_chttpd_config(x_forwarded_host, "X-Forwarded-Host")),
+       ?assertEqual(undefined, 
chttpd_util:get_chttpd_config('WWW-Authenticate')),
+       ?assertEqual("false", chttpd_util:get_chttpd_config(enable_cors, 
"true")).
+

Review comment:
       While it's good to test all the new options, what we should be after is 
to test coverage of behavior. Try to set a setting in setup/0 in `httpd` only 
then check how we read it, then set it in `chttpd` only, then both in `httpd` 
and `chttpd`, then neither (and it would use the default though your first test 
suite `get_chttpd_config_with_undefined_option` covers that case).




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to