diff options
author | Jan Lehnardt <jan@apache.org> | 2008-08-20 14:18:05 +0000 |
---|---|---|
committer | Jan Lehnardt <jan@apache.org> | 2008-08-20 14:18:05 +0000 |
commit | 83af9a01292b5324de651ed90199f61be8d9eae7 (patch) | |
tree | cce4408d58132b37f620e033ccc0c2fac57d93ae /test | |
parent | 4700dd67f03c020c3799a4bf161eadfacbf420cb (diff) |
add missing files
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@687339 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile.am | 20 | ||||
-rw-r--r-- | test/couch_config_test.erl | 43 | ||||
-rw-r--r-- | test/couch_config_writer_test.erl | 181 | ||||
-rw-r--r-- | test/runner.erl | 67 | ||||
-rw-r--r-- | test/runner.sh | 3 |
5 files changed, 314 insertions, 0 deletions
diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 00000000..47227fc8 --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,20 @@ +## 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. + +TESTS = runner.sh + +check_PROGRAMS = runner.beam + +CLEANFILES = test.ini + +runner.beam: runner.erl + $(ERLC) $< diff --git a/test/couch_config_test.erl b/test/couch_config_test.erl new file mode 100644 index 00000000..b9dc71ad --- /dev/null +++ b/test/couch_config_test.erl @@ -0,0 +1,43 @@ +% couch_config module test suote + +% Set up test suite +% ?MODULE_test() returns a list of functions +% that run the actual tests. +couch_config_test() -> + [ + fun() -> store_tuples() end, + fun() -> store_strings() end, + fun() -> store_numbers() end, + fun() -> store_tuple_key() end + ]. + + +% test functions + +% test storing different types and see if they come back +% the same way there put in. +store_tuples() -> + store(key, value). + +store_strings() -> + store("key", "value"). + +store_numbers() -> + store("number_key", 12345). + +store_tuple_key() -> + store({key, subkey}, value). + + +store(Key2, Value2) -> + Key = binary_to_list(term_to_binary(Key2)), + Value = binary_to_list(term_to_binary(Value2)), + + couch_config:start_link(["couch.ini"]), + + couch_config:store({"test_module", Key}, Value), + Result = couch_config:get({"test_module", Key}), + couch_config:unset(Key), + + couch_config:terminate(end_of_test, ok), + Value = Result.
\ No newline at end of file diff --git a/test/couch_config_writer_test.erl b/test/couch_config_writer_test.erl new file mode 100644 index 00000000..b093edff --- /dev/null +++ b/test/couch_config_writer_test.erl @@ -0,0 +1,181 @@ +% couch_config_writer module test suote + +% Set up test suite +% ?MODULE_test() returns a list of functions +% that run the actual tests. +couch_config_writer_test() -> + [ + fun() -> replace_existing_variable() end, + fun() -> append_new_variable() end, + fun() -> append_new_module() end + ]. + + +% test functions +replace_existing_variable() -> + % create file + Contents = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure. + +[CouchDB] +RootDirectory=/Users/jan/Work/runcouch/conf9/var/lib/couchdb +UtilDriverDir=/Users/jan/Work/runcouch/conf9/lib/couchdb/erlang/lib/couch-0.7.3a663206/priv/lib +MaximumDocumentSize=4294967296 ; 4 GB + +[HTTPd] +Port=5984 +BindAddress=127.0.0.1 +DocumentRoot=/Users/jan/Work/runcouch/conf9/share/couchdb/www + +[Log] +File=/Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log +Level=info + +[CouchDB Query Servers] +javascript=/Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js + +[CouchDB Query Server Options] +QueryTimeout=5000 ; 5 seconds +", + + Expect = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure. + +[CouchDB] +RootDirectory=/Users/jan/Work/runcouch/conf9/var/lib/couchdb +UtilDriverDir=/Users/jan/Work/runcouch/conf9/lib/couchdb/erlang/lib/couch-0.7.3a663206/priv/lib +MaximumDocumentSize=4294967296 ; 4 GB + +[HTTPd] +Port=5985 +BindAddress=127.0.0.1 +DocumentRoot=/Users/jan/Work/runcouch/conf9/share/couchdb/www + +[Log] +File=/Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log +Level=info + +[CouchDB Query Servers] +javascript=/Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js + +[CouchDB Query Server Options] +QueryTimeout=5000 ; 5 seconds +", + run_operation_and_compare_results(Contents, Expect, {{"HTTPd", "Port"}, "5985"}). + + +append_new_variable() -> + % create file + Contents = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure. + +[CouchDB] +RootDirectory=/Users/jan/Work/runcouch/conf9/var/lib/couchdb +UtilDriverDir=/Users/jan/Work/runcouch/conf9/lib/couchdb/erlang/lib/couch-0.7.3a663206/priv/lib +MaximumDocumentSize=4294967296 ; 4 GB + +[HTTPd] +Port=5984 +BindAddress=127.0.0.1 +DocumentRoot=/Users/jan/Work/runcouch/conf9/share/couchdb/www + +[Log] +File=/Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log +Level=info + +[CouchDB Query Servers] +javascript=/Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js + +[CouchDB Query Server Options] +QueryTimeout=5000 ; 5 seconds +", + + Expect = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure. + +[CouchDB] +RootDirectory=/Users/jan/Work/runcouch/conf9/var/lib/couchdb +UtilDriverDir=/Users/jan/Work/runcouch/conf9/lib/couchdb/erlang/lib/couch-0.7.3a663206/priv/lib +MaximumDocumentSize=4294967296 ; 4 GB + +[HTTPd] +Port=5984 +BindAddress=127.0.0.1 +DocumentRoot=/Users/jan/Work/runcouch/conf9/share/couchdb/www + +FantasyConfiguration=Citation Needed +[Log] +File=/Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log +Level=info + +[CouchDB Query Servers] +javascript=/Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js + +[CouchDB Query Server Options] +QueryTimeout=5000 ; 5 seconds +", + run_operation_and_compare_results(Contents, Expect, {{"HTTPd", "FantasyConfiguration"}, "Citation Needed"}). + + +append_new_module() -> + % create file + Contents = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure. + +[CouchDB] +RootDirectory=/Users/jan/Work/runcouch/conf9/var/lib/couchdb +UtilDriverDir=/Users/jan/Work/runcouch/conf9/lib/couchdb/erlang/lib/couch-0.7.3a663206/priv/lib +MaximumDocumentSize=4294967296 ; 4 GB + +[HTTPd] +Port=5984 +BindAddress=127.0.0.1 +DocumentRoot=/Users/jan/Work/runcouch/conf9/share/couchdb/www + +[Log] +File=/Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log +Level=info + +[CouchDB Query Servers] +javascript=/Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js + +[CouchDB Query Server Options] +QueryTimeout=5000 ; 5 seconds", + + Expect = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure. + +[CouchDB] +RootDirectory=/Users/jan/Work/runcouch/conf9/var/lib/couchdb +UtilDriverDir=/Users/jan/Work/runcouch/conf9/lib/couchdb/erlang/lib/couch-0.7.3a663206/priv/lib +MaximumDocumentSize=4294967296 ; 4 GB + +[HTTPd] +Port=5984 +BindAddress=127.0.0.1 +DocumentRoot=/Users/jan/Work/runcouch/conf9/share/couchdb/www + +[Log] +File=/Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log +Level=info + +[CouchDB Query Servers] +javascript=/Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js + +[CouchDB Query Server Options] +QueryTimeout=5000 ; 5 seconds + +[Erlang] +Option=Value +", + run_operation_and_compare_results(Contents, Expect, {{"Erlang", "Option"}, "Value"}). + +run_operation_and_compare_results(Contents, Expect, Config) -> + Filename = "couch.ini", + file:write_file(Filename, Contents), + + % call replace function + couch_config_writer:save_to_file(Config, Filename), + + % compare new file with expected file + {ok, Result_} = file:read_file(Filename), + Result = binary_to_list(Result_), + + % clean up + % file:delete(Filename), + + Result = Expect. diff --git a/test/runner.erl b/test/runner.erl new file mode 100644 index 00000000..5cf559f3 --- /dev/null +++ b/test/runner.erl @@ -0,0 +1,67 @@ +-module(runner). + +-export([run/0]). +-include("couch_config_test.erl"). +-include("couch_config_writer_test.erl"). + +%% Test Runner +run() -> + % mochiweb tests + % case mochiweb:test() of + % ok -> + % io:format("Mochiweb Tests PASSED~n"); + % _ -> + % io:format("Mochiweb Tests FAILED~n") + % end, + + % CouchDB tests + Tests = lists:flatten([ + couch_config_test(), + couch_config_writer_test() + ]), + run_tests(Tests), + + % we're done, get out of here + halt(). + +run_test(TestFun) -> + io:format(" ~s ", [proplists:get_value( + name, + erlang:fun_info(TestFun))]), + try TestFun() of + _ -> + io:format("[PASSED]~n", []), + passed + catch + _:{skipped, Reason} -> + io:format("[SKIPPED]~n", []), + io:format(" reason: ~s~n", [Reason]), + skipped; + _:X -> + io:format("[FAILED]~n", []), + io:format("ERROR: ~n======~n~p ~n======~n~n", + [{X, erlang:get_stacktrace()}]), + failed + end. + +run_tests(List) -> + io:format("Running ~p tests...~n", [lists:flatlength(List)]), + + Results = lists:map(fun run_test/1, List), + + Passed = lists:filter( + fun (Result) -> Result =:= passed end, + Results), + + Failed = lists:filter( + fun (Result) -> Result =:= failed end, + Results), + + Skipped = lists:filter( + fun(Result) -> Result =:= skipped end, + Results), + + io:format("PASSED: ~p, FAILED: ~p, SKIPPED: ~p ~n", + [lists:flatlength(Passed), + lists:flatlength(Failed), + lists:flatlength(Skipped)]). diff --git a/test/runner.sh b/test/runner.sh new file mode 100644 index 00000000..ae0f1ef8 --- /dev/null +++ b/test/runner.sh @@ -0,0 +1,3 @@ +#!/bin/sh -e + +erl -noshell -pa ../src/couchdb -pa ../src/mochiweb -eval "runner:run()" |