2020-09-25 04:45:31 +00:00
|
|
|
let
|
|
|
|
|
|
|
|
makeNode = couchpkg: user: passwd:
|
|
|
|
{ pkgs, ... } :
|
|
|
|
|
|
|
|
{ environment.systemPackages = with pkgs; [ jq ];
|
|
|
|
services.couchdb.enable = true;
|
|
|
|
services.couchdb.package = couchpkg;
|
|
|
|
services.couchdb.adminUser = user;
|
|
|
|
services.couchdb.adminPass = passwd;
|
|
|
|
};
|
|
|
|
testuser = "testadmin";
|
|
|
|
testpass = "cowabunga";
|
|
|
|
testlogin = "${testuser}:${testpass}@";
|
|
|
|
|
|
|
|
in import ./make-test-python.nix ({ pkgs, lib, ...}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
{
|
|
|
|
name = "couchdb";
|
|
|
|
meta = with pkgs.stdenv.lib.maintainers; {
|
|
|
|
maintainers = [ fpletz ];
|
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
2020-09-25 04:45:31 +00:00
|
|
|
couchdb1 = makeNode pkgs.couchdb testuser testpass;
|
|
|
|
couchdb2 = makeNode pkgs.couchdb2 testuser testpass;
|
|
|
|
couchdb3 = makeNode pkgs.couchdb3 testuser testpass;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = let
|
2020-09-25 04:45:31 +00:00
|
|
|
curlJqCheck = login: action: path: jqexpr: result:
|
2020-04-24 23:36:52 +00:00
|
|
|
pkgs.writeScript "curl-jq-check-${action}-${path}.sh" ''
|
2020-09-25 04:45:31 +00:00
|
|
|
RESULT=$(curl -X ${action} http://${login}127.0.0.1:5984/${path} | jq -r '${jqexpr}')
|
2020-04-24 23:36:52 +00:00
|
|
|
echo $RESULT >&2
|
|
|
|
if [ "$RESULT" != "${result}" ]; then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
in ''
|
|
|
|
start_all()
|
|
|
|
|
|
|
|
couchdb1.wait_for_unit("couchdb.service")
|
|
|
|
couchdb1.wait_until_succeeds(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck "" "GET" "" ".couchdb" "Welcome"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
couchdb1.wait_until_succeeds(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck "" "GET" "_all_dbs" ". | length" "2"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
2020-09-25 04:45:31 +00:00
|
|
|
couchdb1.succeed("${curlJqCheck testlogin "PUT" "foo" ".ok" "true"}")
|
2020-04-24 23:36:52 +00:00
|
|
|
couchdb1.succeed(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck "" "GET" "_all_dbs" ". | length" "3"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
couchdb1.succeed(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck testlogin "DELETE" "foo" ".ok" "true"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
couchdb1.succeed(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck "" "GET" "_all_dbs" ". | length" "2"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
couchdb2.wait_for_unit("couchdb.service")
|
|
|
|
couchdb2.wait_until_succeeds(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck "" "GET" "" ".couchdb" "Welcome"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
couchdb2.wait_until_succeeds(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck "" "GET" "_all_dbs" ". | length" "0"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
2020-09-25 04:45:31 +00:00
|
|
|
couchdb2.succeed("${curlJqCheck testlogin "PUT" "foo" ".ok" "true"}")
|
2020-04-24 23:36:52 +00:00
|
|
|
couchdb2.succeed(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck "" "GET" "_all_dbs" ". | length" "1"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
couchdb2.succeed(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck testlogin "DELETE" "foo" ".ok" "true"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
couchdb2.succeed(
|
2020-09-25 04:45:31 +00:00
|
|
|
"${curlJqCheck "" "GET" "_all_dbs" ". | length" "0"}"
|
|
|
|
)
|
|
|
|
|
|
|
|
couchdb3.wait_for_unit("couchdb.service")
|
|
|
|
couchdb3.wait_until_succeeds(
|
|
|
|
"${curlJqCheck testlogin "GET" "" ".couchdb" "Welcome"}"
|
|
|
|
)
|
|
|
|
couchdb3.wait_until_succeeds(
|
|
|
|
"${curlJqCheck testlogin "GET" "_all_dbs" ". | length" "0"}"
|
|
|
|
)
|
|
|
|
couchdb3.succeed("${curlJqCheck testlogin "PUT" "foo" ".ok" "true"}")
|
|
|
|
couchdb3.succeed(
|
|
|
|
"${curlJqCheck testlogin "GET" "_all_dbs" ". | length" "1"}"
|
|
|
|
)
|
|
|
|
couchdb3.succeed(
|
|
|
|
"${curlJqCheck testlogin "DELETE" "foo" ".ok" "true"}"
|
|
|
|
)
|
|
|
|
couchdb3.succeed(
|
|
|
|
"${curlJqCheck testlogin "GET" "_all_dbs" ". | length" "0"}"
|
2020-04-24 23:36:52 +00:00
|
|
|
)
|
|
|
|
'';
|
|
|
|
})
|