xref: /5.5.2/couchdb/test/etap/070-couch-db.t (revision f7298f32)
1#!/usr/bin/env escript
2%% -*- erlang -*-
3%%! -smp enable
4
5% Licensed under the Apache License, Version 2.0 (the "License"); you may not
6% use this file except in compliance with the License. You may obtain a copy of
7% the License at
8%
9%   http://www.apache.org/licenses/LICENSE-2.0
10%
11% Unless required by applicable law or agreed to in writing, software
12% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14% License for the specific language governing permissions and limitations under
15% the License.
16
17main(_) ->
18    test_util:init_code_path(),
19
20    etap:plan(4),
21    case (catch test()) of
22        ok ->
23            etap:end_tests();
24        Other ->
25            etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
26            etap:bail(Other)
27    end,
28    ok.
29
30test() ->
31    ets:new(ipv6, [set, protected, named_table]),
32    ets:insert(ipv6, {is_ipv6, false}),
33    couch_server_sup:start_link(test_util:config_files()),
34
35    couch_db:create(<<"etap-test-db">>, []),
36    {ok, AllDbs} = couch_server:all_databases(),
37    etap:ok(lists:member(<<"etap-test-db">>, AllDbs), "Database was created."),
38
39    couch_server:delete(<<"etap-test-db">>, []),
40    {ok, AllDbs2} = couch_server:all_databases(),
41    etap:ok(not lists:member(<<"etap-test-db">>, AllDbs2),
42        "Database was deleted."),
43
44    MkDbName = fun(Int) -> list_to_binary("lru-" ++ integer_to_list(Int)) end,
45
46    lists:foreach(fun(Int) ->
47        {ok, TestDbs} = couch_server:all_databases(),
48        ok = case lists:member(MkDbName(Int), TestDbs) of
49            true -> couch_server:delete(MkDbName(Int), []);
50            _ -> ok
51        end,
52        {ok, Db} = couch_db:create(MkDbName(Int), []),
53        ok = couch_db:close(Db)
54    end, lists:seq(1, 6)),
55
56    {ok, AllDbs3} = couch_server:all_databases(),
57    NumCreated = lists:foldl(fun(Int, Acc) ->
58        true = lists:member(MkDbName(Int), AllDbs3),
59        Acc+1
60    end, 0, lists:seq(1, 6)),
61    etap:is(6, NumCreated, "Created all databases."),
62
63    lists:foreach(fun(Int) ->
64        ok = couch_server:delete(MkDbName(Int), [])
65    end, lists:seq(1, 6)),
66
67    {ok, AllDbs4} = couch_server:all_databases(),
68    NumDeleted = lists:foldl(fun(Int, Acc) ->
69        false = lists:member(MkDbName(Int), AllDbs4),
70        Acc+1
71    end, 0, lists:seq(1, 6)),
72    etap:is(6, NumDeleted, "Deleted all databases."),
73
74    ets:delete(ipv6),
75    ok.
76