1let
2
3 makeNode = couchpkg: user: passwd:
4 { pkgs, ... } :
5
6 { environment.systemPackages = with pkgs; [ jq ];
7 services.couchdb.enable = true;
8 services.couchdb.package = couchpkg;
9 services.couchdb.adminUser = user;
10 services.couchdb.adminPass = passwd;
11 };
12 testuser = "testadmin";
13 testpass = "cowabunga";
14 testlogin = "${testuser}:${testpass}@";
15
16in import ./make-test-python.nix ({ pkgs, lib, ...}:
17
18with lib;
19
20{
21 name = "couchdb";
22 meta = with pkgs.lib.maintainers; {
23 maintainers = [ ];
24 };
25
26 nodes = {
27 couchdb3 = makeNode pkgs.couchdb3 testuser testpass;
28 };
29
30 testScript = let
31 curlJqCheck = login: action: path: jqexpr: result:
32 pkgs.writeScript "curl-jq-check-${action}-${path}.sh" ''
33 RESULT=$(curl -X ${action} http://${login}127.0.0.1:5984/${path} | jq -r '${jqexpr}')
34 echo $RESULT >&2
35 if [ "$RESULT" != "${result}" ]; then
36 exit 1
37 fi
38 '';
39 in ''
40 start_all()
41
42 couchdb3.wait_for_unit("couchdb.service")
43 couchdb3.wait_until_succeeds(
44 "${curlJqCheck testlogin "GET" "" ".couchdb" "Welcome"}"
45 )
46 couchdb3.wait_until_succeeds(
47 "${curlJqCheck testlogin "GET" "_all_dbs" ". | length" "0"}"
48 )
49 couchdb3.succeed("${curlJqCheck testlogin "PUT" "foo" ".ok" "true"}")
50 couchdb3.succeed(
51 "${curlJqCheck testlogin "GET" "_all_dbs" ". | length" "1"}"
52 )
53 couchdb3.succeed(
54 "${curlJqCheck testlogin "DELETE" "foo" ".ok" "true"}"
55 )
56 couchdb3.succeed(
57 "${curlJqCheck testlogin "GET" "_all_dbs" ". | length" "0"}"
58 )
59 couchdb3.succeed(
60 "${curlJqCheck testlogin "GET" "_node/couchdb@127.0.0.1" ".couchdb" "Welcome"}"
61 )
62 '';
63})