1import ./make-test.nix ({ pkgs, lib, ...}:
2
3with lib;
4
5{
6 name = "couchdb";
7 meta = with pkgs.stdenv.lib.maintainers; {
8 maintainers = [ fpletz ];
9 };
10
11 nodes = {
12 couchdb1 =
13 { pkgs, config, ... }:
14
15 { environment.systemPackages = with pkgs; [ jq ];
16 services.couchdb.enable = true;
17 };
18
19 couchdb2 =
20 { pkgs, config, ... }:
21
22 { environment.systemPackages = with pkgs; [ jq ];
23 services.couchdb.enable = true;
24 services.couchdb.package = pkgs.couchdb2;
25 };
26 };
27
28 testScript = let
29 curlJqCheck = action: path: jqexpr: result:
30 pkgs.writeScript "curl-jq-check-${action}-${path}.sh" ''
31 RESULT=$(curl -X ${action} http://127.0.0.1:5984/${path} | jq -r '${jqexpr}')
32 echo $RESULT >&2
33 if [ "$RESULT" != "${result}" ]; then
34 exit 1
35 fi
36 '';
37 in ''
38 startAll;
39
40 $couchdb1->waitForUnit("couchdb.service");
41 $couchdb1->waitUntilSucceeds("${curlJqCheck "GET" "" ".couchdb" "Welcome"}");
42 $couchdb1->waitUntilSucceeds("${curlJqCheck "GET" "_all_dbs" ". | length" "2"}");
43 $couchdb1->succeed("${curlJqCheck "PUT" "foo" ".ok" "true"}");
44 $couchdb1->succeed("${curlJqCheck "GET" "_all_dbs" ". | length" "3"}");
45 $couchdb1->succeed("${curlJqCheck "DELETE" "foo" ".ok" "true"}");
46 $couchdb1->succeed("${curlJqCheck "GET" "_all_dbs" ". | length" "2"}");
47
48 $couchdb2->waitForUnit("couchdb.service");
49 $couchdb2->waitUntilSucceeds("${curlJqCheck "GET" "" ".couchdb" "Welcome"}");
50 $couchdb2->waitUntilSucceeds("${curlJqCheck "GET" "_all_dbs" ". | length" "0"}");
51 $couchdb2->succeed("${curlJqCheck "PUT" "foo" ".ok" "true"}");
52 $couchdb2->succeed("${curlJqCheck "GET" "_all_dbs" ". | length" "1"}");
53 $couchdb2->succeed("${curlJqCheck "DELETE" "foo" ".ok" "true"}");
54 $couchdb2->succeed("${curlJqCheck "GET" "_all_dbs" ". | length" "0"}");
55 '';
56})