at master 1.7 kB view raw
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 17{ pkgs, lib, ... }: 18{ 19 name = "couchdb"; 20 meta.maintainers = [ ]; 21 22 nodes = { 23 couchdb3 = makeNode pkgs.couchdb3 testuser testpass; 24 }; 25 26 testScript = 27 let 28 curlJqCheck = 29 login: action: path: jqexpr: result: 30 pkgs.writeScript "curl-jq-check-${action}-${path}.sh" '' 31 RESULT=$(curl -X ${action} http://${login}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 '' 39 start_all() 40 41 couchdb3.wait_for_unit("couchdb.service") 42 couchdb3.wait_until_succeeds( 43 "${curlJqCheck testlogin "GET" "" ".couchdb" "Welcome"}" 44 ) 45 couchdb3.wait_until_succeeds( 46 "${curlJqCheck testlogin "GET" "_all_dbs" ". | length" "0"}" 47 ) 48 couchdb3.succeed("${curlJqCheck testlogin "PUT" "foo" ".ok" "true"}") 49 couchdb3.succeed( 50 "${curlJqCheck testlogin "GET" "_all_dbs" ". | length" "1"}" 51 ) 52 couchdb3.succeed( 53 "${curlJqCheck testlogin "DELETE" "foo" ".ok" "true"}" 54 ) 55 couchdb3.succeed( 56 "${curlJqCheck testlogin "GET" "_all_dbs" ". | length" "0"}" 57 ) 58 couchdb3.succeed( 59 "${curlJqCheck testlogin "GET" "_node/couchdb@127.0.0.1" ".couchdb" "Welcome"}" 60 ) 61 ''; 62}