summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2008-09-23 15:10:08 +0000
committerJan Lehnardt <jan@apache.org>2008-09-23 15:10:08 +0000
commit3d868b46e62ef51b234f7ab2bc436050d8b9aed0 (patch)
tree7633d1135a96bedb15d534df57de48a63be46c30 /test
parent41634bcfc22171af40042c99fd1324cbaf081a8a (diff)
Fix config file writer issue, where doplicate sections would be created
git-svn-id: https://svn.apache.org/repos/asf/incubator/couchdb/trunk@698202 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'test')
-rw-r--r--test/couch_config_writer_test.erl218
1 files changed, 103 insertions, 115 deletions
diff --git a/test/couch_config_writer_test.erl b/test/couch_config_writer_test.erl
index fd050010..39666f5d 100644
--- a/test/couch_config_writer_test.erl
+++ b/test/couch_config_writer_test.erl
@@ -3,179 +3,167 @@
% Set up test suite
% ?MODULE_test() returns a list of functions
% that run the actual tests.
+% todo, fix replace_existing_variable2 (i.e. reordering)
couch_config_writer_test() ->
[
fun() -> replace_existing_variable() end,
+ fun() -> replace_existing_variable2() end,
+ fun() -> replace_existing_variable3() end,
fun() -> append_new_variable() end,
- fun() -> append_new_module() end
+ fun() -> append_new_module() end,
+ fun() -> overwrite_variable_further_down() end
].
% test functions
replace_existing_variable() ->
% create file
- Contents = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure.
+ Contents = "[section]
+variable = value
-[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
+[another section]
+another_var = another_value
",
- 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
+ Expect = "[section]
+variable = new_value
-[HTTPd]
-Port = 5985
-BindAddress = 127.0.0.1
-DocumentRoot = /Users/jan/Work/runcouch/conf9/share/couchdb/www
+[another section]
+another_var = another_value
+",
+ run_operation_and_compare_results(Contents, Expect, {{"section", "variable"}, "new_value"}).
-[Log]
-File = /Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log
-Level = info
+replace_existing_variable2() ->
+ % create file
+ Contents = "[section]
+variable = value
+variable2 = value2
+variable3 = value3
+variable4 = value4
+
+[another_section]
+another_var = another_value
+",
-[CouchDB Query Servers]
-javascript = /Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js
+ Expect = "[section]
+variable = value
+variable2 = value2
+variable3 = new_value3
+variable4 = value4
-[CouchDB Query Server Options]
-QueryTimeout = 5000 ; 5 seconds
+[another_section]
+another_var = another_value
",
- run_operation_and_compare_results(Contents, Expect, {{"HTTPd", "Port"}, "5985"}).
-
+ run_operation_and_compare_results(Contents, Expect, {{"section", "variable3"}, "new_value3"}).
-append_new_variable() ->
+replace_existing_variable3() ->
% create file
- Contents = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure.
+ Contents = "[first_section]
+var=val
-[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
+[section]
+variable = value
+variable2 = value2
+variable3 = value3
+variable4 = value4
-[HTTPd]
-Port = 5984
-BindAddress = 127.0.0.1
-DocumentRoot = /Users/jan/Work/runcouch/conf9/share/couchdb/www
+[another_section]
+another_var = another_value
+",
-[Log]
-File = /Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log
-Level = info
+ Expect = "[first_section]
+var=val
-[CouchDB Query Servers]
-javascript = /Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js
+[section]
+variable = value
+variable2 = value2
+variable3 = new_value3
+variable4 = value4
-[CouchDB Query Server Options]
-QueryTimeout = 5000 ; 5 seconds
+[another_section]
+another_var = another_value
",
+ run_operation_and_compare_results(Contents, Expect, {{"section", "variable3"}, "new_value3"}).
- 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
+append_new_variable() ->
+ % create file
+ Contents = "[section]
+variable = value
+variable2 = value
-[HTTPd]
-Port = 5984
-BindAddress = 127.0.0.1
-DocumentRoot = /Users/jan/Work/runcouch/conf9/share/couchdb/www
+[another_section]
+another_var = another_value
+",
-FantasyConfiguration = Citation Needed
-[Log]
-File = /Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log
-Level = info
+ Expect = "[section]
+variable = value
+variable2 = value
-[CouchDB Query Servers]
-javascript = /Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js
+fantasy_variable = Citation Needed
-[CouchDB Query Server Options]
-QueryTimeout = 5000 ; 5 seconds
+[another_section]
+another_var = another_value
",
- run_operation_and_compare_results(Contents, Expect, {{"HTTPd", "FantasyConfiguration"}, "Citation Needed"}).
+ run_operation_and_compare_results(Contents, Expect, {{"section", "fantasy_variable"}, "Citation Needed"}).
append_new_module() ->
% create file
- Contents = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure.
+ Contents = "[section]
+variable = value
-[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
+[another_section]
+another_var = another_value
+",
-[HTTPd]
-Port = 5984
-BindAddress = 127.0.0.1
-DocumentRoot = /Users/jan/Work/runcouch/conf9/share/couchdb/www
+ Expect = "[section]
+variable = value
-[Log]
-File = /Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log
-Level = info
+[another_section]
+another_var = another_value
-[CouchDB Query Servers]
-javascript = /Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js
+[one_more_section]
+favourite_food = cupcakes
+",
+ run_operation_and_compare_results(Contents, Expect, [{{"one_more_section", "favourite_food"}, "cupcakes"}]).
-[CouchDB Query Server Options]
-QueryTimeout = 5000 ; 5 seconds",
+overwrite_variable_further_down() ->
+ % create file
+ Contents = "[section]
+variable = value
- Expect = "; etc/couchdb/couch.ini.tpl. Generated from couch.ini.tpl.in by configure.
+[another_section]
+another_var = another_value
+",
-[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
+ Expect = "[section]
+variable = value
-[HTTPd]
-Port = 5984
-BindAddress = 127.0.0.1
-DocumentRoot = /Users/jan/Work/runcouch/conf9/share/couchdb/www
+[another_section]
+another_var = another_value
-[Log]
-File = /Users/jan/Work/runcouch/conf9/var/log/couchdb/couch.log
-Level = info
+[erlang]
+option = value
-[CouchDB Query Servers]
-javascript = /Users/jan/Work/runcouch/conf9/bin/couchjs /Users/jan/Work/runcouch/conf9/share/couchdb/server/main.js
+option2 = value2
+",
+ run_operation_and_compare_results(Contents, Expect, [{{"erlang", "option"}, "value"}, {{"erlang", "option2"}, "value2"}]).
-[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) when not is_list(Config) ->
+ run_operation_and_compare_results(Contents, Expect, [Config]);
run_operation_and_compare_results(Contents, Expect, Config) ->
Filename = "local.ini",
file:write_file(Filename, Contents),
% call replace function
- couch_config_writer:save_to_file(Config, Filename),
+ [couch_config_writer:save_to_file(ConfigVar, Filename) || ConfigVar <- Config],
% compare new file with expected file
{ok, Result_} = file:read_file(Filename),
Result = binary_to_list(Result_),
% clean up
- file:delete(Filename),
+ % file:delete(Filename),
Result = Expect.