1let
2 makeNode =
3 couchpkg: user: passwd:
4 { pkgs, ... }:
5
6 {
7 environment.systemPackages = [ pkgs.jq ];
8 services.couchdb.enable = true;
9 services.couchdb.package = couchpkg;
10 services.couchdb.adminUser = user;
11 services.couchdb.adminPass = passwd;
12 };
13 testuser = "testadmin";
14 testpass = "cowabunga";
15 testlogin = "${testuser}:${testpass}@";
16in
17import ./make-test-python.nix (
18 { pkgs, lib, ... }:
19 {
20 name = "couchdb";
21 meta.maintainers = [ ];
22
23 nodes = {
24 couchdb3 = makeNode pkgs.couchdb3 testuser testpass;
25 };
26
27 testScript =
28 let
29 curlJqCheck =
30 login: action: path: jqexpr: result:
31 pkgs.writeScript "curl-jq-check-${action}-${path}.sh" ''
32 RESULT=$(curl -X ${action} http://${login}127.0.0.1:5984/${path} | jq -r '${jqexpr}')
33 echo $RESULT >&2
34 if [ "$RESULT" != "${result}" ]; then
35 exit 1
36 fi
37 '';
38 in
39 ''
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 }
64)