http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/200-view-group-no-db-leaks.t ---------------------------------------------------------------------- diff --git a/src/test/etap/200-view-group-no-db-leaks.t b/src/test/etap/200-view-group-no-db-leaks.t index b711ac8..dddf43b 100755 --- a/src/test/etap/200-view-group-no-db-leaks.t +++ b/src/test/etap/200-view-group-no-db-leaks.t @@ -1,5 +1,6 @@ #!/usr/bin/env escript %% -*- erlang -*- +%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap % 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 @@ -66,6 +67,8 @@ main(_) -> test() -> couch_server_sup:start_link(test_util:config_files()), + couch_index_sup:start_link(), + timer:sleep(1000), put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")), put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))), @@ -193,7 +196,7 @@ wait_view_compact_done(N) -> 200 -> ok; _ -> etap:bail("Invalid view group info.") end, - {Info} = ejson:decode(Body), + {Info} = couch_util:json_decode(Body), {IndexInfo} = couch_util:get_value(<<"view_index">>, Info), CompactRunning = couch_util:get_value(<<"compact_running">>, IndexInfo), case CompactRunning of @@ -292,7 +295,7 @@ query_view(ExpectedRowCount, ExpectedRowValue, Stale) -> [], get), etap:is(Code, 200, "got view response"), - {Props} = ejson:decode(Body), + {Props} = couch_util:json_decode(Body), Rows = couch_util:get_value(<<"rows">>, Props, []), etap:is(length(Rows), ExpectedRowCount, "result set has correct # of rows"), lists:foreach(
http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/201-view-group-shutdown.t ---------------------------------------------------------------------- diff --git a/src/test/etap/201-view-group-shutdown.t b/src/test/etap/201-view-group-shutdown.t index c51ec44..b4927fa 100755 --- a/src/test/etap/201-view-group-shutdown.t +++ b/src/test/etap/201-view-group-shutdown.t @@ -1,5 +1,6 @@ #!/usr/bin/env escript %% -*- erlang -*- +%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap % 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 @@ -67,6 +68,7 @@ main(_) -> test() -> couch_server_sup:start_link(test_util:config_files()), + couch_index_sup:start_link(), ok = couch_config:set("couchdb", "max_dbs_open", "3", false), ok = couch_config:set("couchdb", "delayed_commits", "false", false), crypto:start(), http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/210-os-proc-pool.t ---------------------------------------------------------------------- diff --git a/src/test/etap/210-os-proc-pool.t b/src/test/etap/210-os-proc-pool.t index d80707e..fd88780 100755 --- a/src/test/etap/210-os-proc-pool.t +++ b/src/test/etap/210-os-proc-pool.t @@ -1,5 +1,7 @@ #!/usr/bin/env escript %% -*- erlang -*- +%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap + % 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://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/220-compaction-daemon.t ---------------------------------------------------------------------- diff --git a/src/test/etap/220-compaction-daemon.t b/src/test/etap/220-compaction-daemon.t index 4c63b66..7f3f43b 100755 --- a/src/test/etap/220-compaction-daemon.t +++ b/src/test/etap/220-compaction-daemon.t @@ -1,5 +1,6 @@ #!/usr/bin/env escript %% -*- erlang -*- +%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap % 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 @@ -37,6 +38,7 @@ main(_) -> test() -> couch_server_sup:start_link(test_util:config_files()), + couch_index_sup:start_link(), timer:sleep(1000), put(addr, couch_config:get("httpd", "bind_address", "127.0.0.1")), put(port, integer_to_list(mochiweb_socket_server:get(couch_httpd, port))), http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/230-pbkfd2.t ---------------------------------------------------------------------- diff --git a/src/test/etap/230-pbkfd2.t b/src/test/etap/230-pbkfd2.t index d980ef6..5a5b615 100644 --- a/src/test/etap/230-pbkfd2.t +++ b/src/test/etap/230-pbkfd2.t @@ -1,5 +1,6 @@ #!/usr/bin/env escript %% -*- erlang -*- +%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap % 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 http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/231-cors.t ---------------------------------------------------------------------- diff --git a/src/test/etap/231-cors.t b/src/test/etap/231-cors.t index dd08ca8..5bad77a 100644 --- a/src/test/etap/231-cors.t +++ b/src/test/etap/231-cors.t @@ -1,5 +1,6 @@ #!/usr/bin/env escript %% -*- erlang -*- +%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap % 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 http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/250-upgrade-legacy-view-files.t ---------------------------------------------------------------------- diff --git a/src/test/etap/250-upgrade-legacy-view-files.t b/src/test/etap/250-upgrade-legacy-view-files.t index e720b1c..0d954b8 100644 --- a/src/test/etap/250-upgrade-legacy-view-files.t +++ b/src/test/etap/250-upgrade-legacy-view-files.t @@ -1,5 +1,7 @@ #!/usr/bin/env escript %% -*- erlang -*- +%%! -pa ./src/deps/*/ebin -pa ./src/apps/*/ebin -pa ./src/test/etap + % 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 @@ -28,6 +30,7 @@ main(_) -> test() -> couch_server_sup:start_link(test_util:config_files()), + couch_index_sup:start_link(), % commit sofort ok = couch_config:set("query_server_config", "commit_freq", "0"), @@ -38,7 +41,7 @@ test() -> ok. fixture_path() -> - test_util:source_file("test/etap/fixtures"). + test_util:build_file("test/etap/fixtures"). old_db() -> fixture_path() ++ "/" ++ old_db_name(). http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/Makefile.am ---------------------------------------------------------------------- diff --git a/src/test/etap/Makefile.am b/src/test/etap/Makefile.am deleted file mode 100644 index 66048a9..0000000 --- a/src/test/etap/Makefile.am +++ /dev/null @@ -1,108 +0,0 @@ -## 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. - -noinst_SCRIPTS = run -noinst_DATA = test_util.beam test_web.beam - -noinst_PROGRAMS = test_cfg_register -test_cfg_register_SOURCES = test_cfg_register.c -test_cfg_register_CFLAGS = -D_BSD_SOURCE - -%.beam: %.erl - $(ERLC) $< - -run: run.tpl - sed -e "s|%abs_top_srcdir%|@abs_top_srcdir@|g" \ - -e "s|%abs_top_builddir%|@abs_top_builddir@|g" > \ - $@ < $< - chmod +x $@ - -# @@ wildcards are NOT portable, please replace with clean-local rules -CLEANFILES = run *.beam - -DISTCLEANFILES = temp.* - -fixture_files = \ - fixtures/3b835456c235b1827e012e25666152f3.view \ - fixtures/test.couch - -tap_files = \ - 001-load.t \ - 002-icu-driver.t \ - 010-file-basics.t \ - 011-file-headers.t \ - 020-btree-basics.t \ - 021-btree-reductions.t \ - 030-doc-from-json.t \ - 031-doc-to-json.t \ - 040-util.t \ - 041-uuid-gen-id.ini \ - 041-uuid-gen-seq.ini \ - 041-uuid-gen-utc.ini \ - 041-uuid-gen.t \ - 042-work-queue.t \ - 050-stream.t \ - 060-kt-merging.t \ - 061-kt-missing-leaves.t \ - 062-kt-remove-leaves.t \ - 063-kt-get-leaves.t \ - 064-kt-counting.t \ - 065-kt-stemming.t \ - 070-couch-db.t \ - 072-cleanup.t \ - 073-changes.t \ - 074-doc-update-conflicts.t \ - 075-auth-cache.t \ - 076-file-compression.t \ - 077-couch-db-fast-db-delete-create.t \ - 080-config-get-set.t \ - 081-config-override.1.ini \ - 081-config-override.2.ini \ - 081-config-override.t \ - 082-config-register.t \ - 083-config-no-files.t \ - 090-task-status.t \ - 100-ref-counter.t \ - 120-stats-collect.t \ - 121-stats-aggregates.cfg \ - 121-stats-aggregates.ini \ - 121-stats-aggregates.t \ - 130-attachments-md5.t \ - 140-attachment-comp.t \ - 150-invalid-view-seq.t \ - 160-vhosts.t \ - 170-os-daemons.es \ - 170-os-daemons.t \ - 171-os-daemons-config.es \ - 171-os-daemons-config.t \ - 172-os-daemon-errors.1.sh \ - 172-os-daemon-errors.2.sh \ - 172-os-daemon-errors.3.sh \ - 172-os-daemon-errors.4.sh \ - 172-os-daemon-errors.t \ - 173-os-daemon-cfg-register.t \ - 180-http-proxy.ini \ - 180-http-proxy.t \ - 190-json-stream-parse.t \ - 200-view-group-no-db-leaks.t \ - 201-view-group-shutdown.t \ - 210-os-proc-pool.t \ - 220-compaction-daemon.t \ - 230-pbkfd2.t \ - 231-cors.t \ - 250-upgrade-legacy-view-files.t - -EXTRA_DIST = \ - run.tpl \ - test_web.erl \ - $(fixture_files) \ - $(tap_files) http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/run.tpl ---------------------------------------------------------------------- diff --git a/src/test/etap/run.tpl b/src/test/etap/run.tpl deleted file mode 100644 index d6d6dbe..0000000 --- a/src/test/etap/run.tpl +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -e - -# 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. - -SRCDIR="%abs_top_srcdir%" -BUILDDIR="%abs_top_builddir%" -export ERL_LIBS="$BUILDDIR/src/:$ERL_LIBS" -export ERL_FLAGS="$ERL_FLAGS -pa $BUILDDIR/test/etap/" - -if test $# -eq 1; then - OPTS="" - TGT=$1 -else - OPTS=$1 - TGT=$2 -fi - -if test -f $TGT; then - prove $OPTS $TGT -else - prove $OPTS $TGT/*.t -fi http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/test_util.erl ---------------------------------------------------------------------- diff --git a/src/test/etap/test_util.erl b/src/test/etap/test_util.erl new file mode 100644 index 0000000..7bedfd6 --- /dev/null +++ b/src/test/etap/test_util.erl @@ -0,0 +1,158 @@ +% 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(test_util). + +-export([init_code_path/0]). +-export([source_file/1, build_file/1, test_file/1, config_files/0]). +-export([run/2]). +-export([request/3, request/4]). + +builddir() -> + Current = filename:dirname(code:which(?MODULE)), + filename:absname(filename:join([Current, "..", ".."])). + + + + +srcdir() -> + filename:join([builddir(), "apps"]). + +depsdir() -> + filename:join([builddir(), "deps"]). + +testdir() -> + filename:join([builddir(), "test", "out"]). + +%% +%% Given a list of key value pairs, for each string value attempt to +%% render it using Dict as the context. Storing the result in Dict as Key. +%% +resolve_variables([], Dict) -> + Dict; +resolve_variables([{Key, Value0} | Rest], Dict) when is_integer(Value0) -> + Value = render(list_to_binary(integer_to_list(Value0)), Dict), + resolve_variables(Rest, dict:store(Key, Value, Dict)); +resolve_variables([{Key, Value0} | Rest], Dict) when is_list(Value0) -> + Value = render(list_to_binary(Value0), Dict), + resolve_variables(Rest, dict:store(Key, Value, Dict)); +resolve_variables([{Key, {list, Dicts}} | Rest], Dict) when is_list(Dicts) -> + %% just un-tag it so mustache can use it + resolve_variables(Rest, dict:store(Key, Dicts, Dict)); +resolve_variables([_Pair | Rest], Dict) -> + resolve_variables(Rest, Dict). + +%% +%% Render a binary to a string, using mustache and the specified context +%% + +render(Bin, Context) -> + %% Be sure to escape any double-quotes before rendering... + ReOpts = [global, {return, list}], + Str0 = re:replace(Bin, "\\\\", "\\\\\\", ReOpts), + Str1 = re:replace(Str0, "\"", "\\\\\"", ReOpts), + mustache:render(Str1, Context). + + +init_config() -> + {ok, Vars} = file:consult(filename:join([builddir(), "test", + "vars.config"])), + + Vars1 = resolve_variables(Vars, dict:from_list([{testdir, testdir()}])), + + %% create test config + {ok, Bin} = file:read_file(filename:join([builddir(), "etc", + "couchdb", "couch.ini"])), + + Rendered = render(Bin, Vars1), + ok = file:write_file(filename:join([testdir(), "couch_test.ini"]), + Rendered), + + %% load config file path in the env + IniFiles = config_files(), + application:set_env(couch, config_files, IniFiles). + +init_code_path() -> + lists:foreach(fun(Name) -> + code:add_patha(filename:join([depsdir(), Name, "ebin"])) + end, filelib:wildcard("*", depsdir())), + + lists:foreach(fun(Name) -> + code:add_patha(filename:join([srcdir(), Name, "ebin"])) + end, filelib:wildcard("*", srcdir())), + + code:add_patha(filename:join([builddir(), "test", "etap"])), + + %% init config + application:load(couch), + init_config(). + + +source_file(Name) -> + filename:join([srcdir(), Name]). + +build_file(Name) -> + filename:join([builddir(), Name]). + +test_file(Name) -> + filename:join([testdir(), Name]). + +config_files() -> + [ + filename:join([testdir(), "couch_test.ini"]), + filename:join([builddir(), "etc", "couchdb", "local.ini"]) + ]. + + +run(Plan, Fun) -> + test_util:init_code_path(), + etap:plan(Plan), + case (catch Fun()) of + ok -> + etap:end_tests(); + Other -> + etap:diag(io_lib:format("Test died abnormally:~n~p", [Other])), + timer:sleep(500), + etap:bail(Other) + end, + ok. + + +request(Url, Headers, Method) -> + request(Url, Headers, Method, []). + +request(Url, Headers, Method, Body) -> + request(Url, Headers, Method, Body, 3). + +request(_Url, _Headers, _Method, _Body, 0) -> + {error, request_failed}; +request(Url, Headers, Method, Body, N) -> + case code:is_loaded(ibrowse) of + false -> + {ok, _} = ibrowse:start(); + _ -> + ok + end, + io:format("start this fucking request ~p-~p-~p~n", [Url, Headers, + Method]), + case ibrowse:send_req(Url, Headers, Method, Body) of + {ok, Code0, RespHeaders, RespBody0} -> + Code = list_to_integer(Code0), + RespBody = iolist_to_binary(RespBody0), + {ok, Code, RespHeaders, RespBody}; + {error, {'EXIT', {normal, _}}} -> + % Connection closed right after a successful request that + % used the same connection. + request(Url, Headers, Method, Body, N - 1); + Error -> + Error + end. http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/etap/test_util.erl.in ---------------------------------------------------------------------- diff --git a/src/test/etap/test_util.erl.in b/src/test/etap/test_util.erl.in deleted file mode 100644 index 352714e..0000000 --- a/src/test/etap/test_util.erl.in +++ /dev/null @@ -1,94 +0,0 @@ -% 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(test_util). - --export([init_code_path/0]). --export([source_file/1, build_file/1, config_files/0]). --export([run/2]). --export([request/3, request/4]). - -srcdir() -> - "@abs_top_srcdir@". - -builddir() -> - "@abs_top_builddir@". - -init_code_path() -> - Paths = [ - "etap", - "couchdb", - "ejson", - "erlang-oauth", - "ibrowse", - "mochiweb", - "snappy" - ], - lists:foreach(fun(Name) -> - code:add_patha(filename:join([builddir(), "src", Name])) - end, Paths). - -source_file(Name) -> - filename:join([srcdir(), Name]). - -build_file(Name) -> - filename:join([builddir(), Name]). - -config_files() -> - [ - build_file("etc/couchdb/default_dev.ini"), - source_file("test/random_port.ini"), - build_file("etc/couchdb/local_dev.ini") - ]. - - -run(Plan, Fun) -> - test_util:init_code_path(), - etap:plan(Plan), - case (catch Fun()) of - ok -> - etap:end_tests(); - Other -> - etap:diag(io_lib:format("Test died abnormally:~n~p", [Other])), - timer:sleep(500), - etap:bail(Other) - end, - ok. - - -request(Url, Headers, Method) -> - request(Url, Headers, Method, []). - -request(Url, Headers, Method, Body) -> - request(Url, Headers, Method, Body, 3). - -request(_Url, _Headers, _Method, _Body, 0) -> - {error, request_failed}; -request(Url, Headers, Method, Body, N) -> - case code:is_loaded(ibrowse) of - false -> - {ok, _} = ibrowse:start(); - _ -> - ok - end, - case ibrowse:send_req(Url, Headers, Method, Body) of - {ok, Code0, RespHeaders, RespBody0} -> - Code = list_to_integer(Code0), - RespBody = iolist_to_binary(RespBody0), - {ok, Code, RespHeaders, RespBody}; - {error, {'EXIT', {normal, _}}} -> - % Connection closed right after a successful request that - % used the same connection. - request(Url, Headers, Method, Body, N - 1); - Error -> - Error - end. http://git-wip-us.apache.org/repos/asf/couchdb/blob/78c1a3f9/src/test/vars.config ---------------------------------------------------------------------- diff --git a/src/test/vars.config b/src/test/vars.config new file mode 100644 index 0000000..7b08fd6 --- /dev/null +++ b/src/test/vars.config @@ -0,0 +1,38 @@ +%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ft=erlang ts=4 sw=4 et + +% 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. + +%% Platform-specific installation paths +{platform_bin_dir, "{{testdir}}/bin"}. +{platform_data_dir, "{{testdir}}/data"}. +{platform_view_dir, "{{testdir}}/data"}. +{platform_etc_dir, "{{testdir}}/etc"}. +{platform_lib_dir, "{{testdir}}/lib"}. +{platform_log_dir, "{{testdir}}/log"}. +{platform_run_dir, "{{testdir}}/run"}. +{platform_share_dir, "{{testdir}}/share"}. + +%% vendor info +{vendor_name, "The Apache Software Foundation"}. + +%% couchjs name +{couchjs_name, "couchjs"}. + + +%% app config +{couchdb_ip, "0.0.0.0"}. +{couchdb_port, 0}. +{ssl_port, 6986}. +{sasl_error_log, "{{testdir}}/log/sasl-error.log"}. +{sasl_log_dir, "{{testdir}}/log/sasl"}.
