diff --git a/.github/workflows/nginx_test.yml b/.github/workflows/side-service-test.yml similarity index 75% rename from .github/workflows/nginx_test.yml rename to .github/workflows/side-service-test.yml index a11e03666d3..d4dbb9dcd97 100644 --- a/.github/workflows/nginx_test.yml +++ b/.github/workflows/side-service-test.yml @@ -1,4 +1,4 @@ -name: Nginx test +name: Test nginx and haproxy on: [push, pull_request] @@ -18,3 +18,7 @@ jobs: cd nginx make test ) + ( + cd haproxy/tests + make test + ) diff --git a/haproxy/Dockerfile b/haproxy/Dockerfile index 3f7e71f9571..4584a7ec5a2 100644 --- a/haproxy/Dockerfile +++ b/haproxy/Dockerfile @@ -8,5 +8,6 @@ RUN chmod +x /entrypoint.sh ADD default_frontend.cfg /usr/local/etc/haproxy ADD backend.cfg.template /usr/local/etc/haproxy COPY scripts /usr/local/etc/haproxy/ +COPY errors/*.http /usr/local/etc/haproxy/errors/ ENTRYPOINT ["/entrypoint.sh"] diff --git a/haproxy/README.md b/haproxy/README.md index 75a1625552c..8206ba715cd 100644 --- a/haproxy/README.md +++ b/haproxy/README.md @@ -28,8 +28,7 @@ In your docker-compose.yml template, the HAproxy container declaration will requ - HAPROXY_IP: This should be the docker service name, `fqdn`, or set to `0.0.0.0`. If not set, our templates will default this to be a service name of `haproxy`. *Note*: For Docker Desktop on Mac users, if you wish to expose HAproxy to your host, you will have to set this as `0.0.0.0`, to expose it as `localhost` outside of the docker network. - HAPROXY_PORT: The port you wish HAProxy to run on. Defaults to 5984. -- COUCHDB1_SERVER: The docker service name or fqdn of the first CouchDB server. Defaults to couchdb-1.local in our templates. -- COUCHDB2_SERVER: The docker service name or fqdn of the second CouchDB server. Defaults to couchdb-2.local in our templates. -- COUCHDB3_SERVER: The docker service name or fqdn of the third CouchDB server. Defaults to couchdb-3.local in our templates. +- COUCHDB_SERVERS: Comma separated list of the docker service name or fqdn of the CouchDB servers. Example: `couchdb-1.local,couchdb-2.local,couchdb-3.local`. - COUCHDB_USER: The admininstrator that created the couchdb cluster - COUCHDB_PASSWORD: The above admin's password +- HEALTHCHECK_ADDR: Address to the haproxy healthcheck service diff --git a/haproxy/default_frontend.cfg b/haproxy/default_frontend.cfg index 34354dbc4da..b433c7ca306 100644 --- a/haproxy/default_frontend.cfg +++ b/haproxy/default_frontend.cfg @@ -8,6 +8,27 @@ global tune.bufsize 32768 tune.buffers.limit 60000 +http-errors json + errorfile 200 /usr/local/etc/haproxy/errors/200-json.http + errorfile 400 /usr/local/etc/haproxy/errors/400-json.http + errorfile 401 /usr/local/etc/haproxy/errors/401-json.http + errorfile 403 /usr/local/etc/haproxy/errors/403-json.http + errorfile 404 /usr/local/etc/haproxy/errors/404-json.http + errorfile 405 /usr/local/etc/haproxy/errors/405-json.http + errorfile 407 /usr/local/etc/haproxy/errors/407-json.http + errorfile 408 /usr/local/etc/haproxy/errors/408-json.http + errorfile 410 /usr/local/etc/haproxy/errors/410-json.http + errorfile 413 /usr/local/etc/haproxy/errors/413-json.http + errorfile 421 /usr/local/etc/haproxy/errors/421-json.http + errorfile 422 /usr/local/etc/haproxy/errors/422-json.http + errorfile 425 /usr/local/etc/haproxy/errors/425-json.http + errorfile 429 /usr/local/etc/haproxy/errors/429-json.http + errorfile 500 /usr/local/etc/haproxy/errors/500-json.http + errorfile 501 /usr/local/etc/haproxy/errors/501-json.http + errorfile 502 /usr/local/etc/haproxy/errors/502-json.http + errorfile 503 /usr/local/etc/haproxy/errors/503-json.http + errorfile 504 /usr/local/etc/haproxy/errors/504-json.http + defaults mode http option http-ignore-probes @@ -19,6 +40,9 @@ defaults timeout server 360000000 timeout connect 1500000 timeout http-keep-alive 5m + + errorfiles json + stats enable stats refresh 30s stats auth $COUCHDB_USER:$COUCHDB_PASSWORD diff --git a/haproxy/entrypoint.sh b/haproxy/entrypoint.sh index 46c32d6115b..d5e80618894 100644 --- a/haproxy/entrypoint.sh +++ b/haproxy/entrypoint.sh @@ -9,7 +9,7 @@ BACKEND="/usr/local/etc/haproxy/backend.cfg" cp /usr/local/etc/haproxy/backend.cfg.template $BACKEND for COUCHDB_SERVER in ${COUCHDB_SERVERS//,/ } do - printf " server $COUCHDB_SERVER $COUCHDB_SERVER:5984 check agent-check agent-inter 5s agent-addr $HEALTHCHECK_ADDR agent-port 5555\n" >> $BACKEND + echo " server $COUCHDB_SERVER $COUCHDB_SERVER:5984 check agent-check agent-inter 5s agent-addr $HEALTHCHECK_ADDR agent-port 5555" >> $BACKEND done # Place environment variables into config @@ -18,8 +18,9 @@ envsubst < $BACKEND #Write pw for healthcheck subshell to work mkdir -p /srv/storage/haproxy/passwd -echo $COUCHDB_USER > /srv/storage/haproxy/passwd/username -echo $COUCHDB_PASSWORD > /srv/storage/haproxy/passwd/admin +echo "$COUCHDB_USER" > /srv/storage/haproxy/passwd/username +echo "$COUCHDB_PASSWORD" > /srv/storage/haproxy/passwd/admin # Start haproxy exec /usr/local/bin/docker-entrypoint.sh -f $DEFAULT -f $BACKEND + diff --git a/haproxy/errors/200-json.http b/haproxy/errors/200-json.http new file mode 100644 index 00000000000..e27da708fc5 --- /dev/null +++ b/haproxy/errors/200-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 200 OK +Content-length: 75 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "200 OK", + "reason": "Service ready", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/400-json.http b/haproxy/errors/400-json.http new file mode 100644 index 00000000000..af8b24d33c3 --- /dev/null +++ b/haproxy/errors/400-json.http @@ -0,0 +1,11 @@ +HTTP/1.1 400 Bad request +Content-length: 107 +Connection: Close +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "400 Bad request", + "reason": "Your browser sent an invalid request", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/401-json.http b/haproxy/errors/401-json.http new file mode 100644 index 00000000000..d17cdd3f1c9 --- /dev/null +++ b/haproxy/errors/401-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 401 Unauthorized +Content-length: 129 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "401 Unauthorized", + "reason": "You need a valid user and password to access this content", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/403-json.http b/haproxy/errors/403-json.http new file mode 100644 index 00000000000..19b7f38d87e --- /dev/null +++ b/haproxy/errors/403-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 403 Forbidden +Content-length: 110 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "403 Forbidden", + "reason": "Request forbidden by administrative rules", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/404-json.http b/haproxy/errors/404-json.http new file mode 100644 index 00000000000..fd26cfb285f --- /dev/null +++ b/haproxy/errors/404-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 404 Not Found +Content-length: 100 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "404 Not Found", + "reason": "The resource could not be found", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/405-json.http b/haproxy/errors/405-json.http new file mode 100644 index 00000000000..62a7a86494e --- /dev/null +++ b/haproxy/errors/405-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 405 Method Not Allowed +Content-length: 164 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "405 Method Not Allowed", + "reason": "A request was made of a resource using a request method not supported by that resource", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/407-json.http b/haproxy/errors/407-json.http new file mode 100644 index 00000000000..cd8c98d9cc0 --- /dev/null +++ b/haproxy/errors/407-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 407 Unauthorized +Content-length: 129 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "407 Unauthorized", + "reason": "You need a valid user and password to access this content", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/408-json.http b/haproxy/errors/408-json.http new file mode 100644 index 00000000000..82069a5346f --- /dev/null +++ b/haproxy/errors/408-json.http @@ -0,0 +1,11 @@ +HTTP/1.1 408 Request Time-out +Content-length: 127 +Connection: Close +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "408 Request Time-out", + "reason": "Your browser didn't send a complete request in time", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/410-json.http b/haproxy/errors/410-json.http new file mode 100644 index 00000000000..9fc1a76242d --- /dev/null +++ b/haproxy/errors/410-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 410 Gone +Content-length: 131 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "410 Gone", + "reason": "The resource is no longer available and will not be available again", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/413-json.http b/haproxy/errors/413-json.http new file mode 100644 index 00000000000..13f4e65a127 --- /dev/null +++ b/haproxy/errors/413-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 413 Payload Too Large +Content-length: 123 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "413 Payload Too Large", + "reason": "The request entity exceeds the maximum allowed", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/421-json.http b/haproxy/errors/421-json.http new file mode 100644 index 00000000000..8b620e31e63 --- /dev/null +++ b/haproxy/errors/421-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 421 Misdirected Request +Content-length: 121 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "421 Misdirected Request", + "reason": "Request sent to a non-authoritative server", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/422-json.http b/haproxy/errors/422-json.http new file mode 100644 index 00000000000..3f3d4510f13 --- /dev/null +++ b/haproxy/errors/422-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 422 Unprocessable Content +Content-length: 133 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "422 Unprocessable Content", + "reason": "The server cannot process the contained instructions", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/425-json.http b/haproxy/errors/425-json.http new file mode 100644 index 00000000000..c5a8a69f676 --- /dev/null +++ b/haproxy/errors/425-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 425 Too Early +Content-length: 97 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "425 Too Early", + "reason": "Your browser sent early data", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/429-json.http b/haproxy/errors/429-json.http new file mode 100644 index 00000000000..6a709ce7d06 --- /dev/null +++ b/haproxy/errors/429-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 429 Too Many Requests +Content-length: 134 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "429 Too Many Requests", + "reason": "You have sent too many requests in a given amount of time", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/500-json.http b/haproxy/errors/500-json.http new file mode 100644 index 00000000000..55a38063ab1 --- /dev/null +++ b/haproxy/errors/500-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 500 Internal Server Error +Content-length: 114 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "500 Internal Server Error", + "reason": "An internal server error occurred", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/501-json.http b/haproxy/errors/501-json.http new file mode 100644 index 00000000000..ad0ec7f138d --- /dev/null +++ b/haproxy/errors/501-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 501 Not Implemented +Content-length: 152 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "501 Not Implemented", + "reason": "The server does not support the functionality required to fulfill the request", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/502-json.http b/haproxy/errors/502-json.http new file mode 100644 index 00000000000..b0dba29235a --- /dev/null +++ b/haproxy/errors/502-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 502 Bad Gateway +Content-length: 124 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "502 Bad Gateway", + "reason": "The server returned an invalid or incomplete response", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/503-json.http b/haproxy/errors/503-json.http new file mode 100644 index 00000000000..d0c9cd01abb --- /dev/null +++ b/haproxy/errors/503-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 503 Service Unavailable +Content-length: 124 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "503 Service Unavailable", + "reason": "No server is available to handle this request", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/504-json.http b/haproxy/errors/504-json.http new file mode 100644 index 00000000000..b281b00e975 --- /dev/null +++ b/haproxy/errors/504-json.http @@ -0,0 +1,10 @@ +HTTP/1.1 504 Gateway Time-out +Content-length: 109 +Cache-Control: no-cache +Content-Type: application/json + +{ + "error": "504 Gateway Time-out", + "reason": "The server didn't respond in time", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/errors/README.md b/haproxy/errors/README.md new file mode 100644 index 00000000000..16c4ef19fb0 --- /dev/null +++ b/haproxy/errors/README.md @@ -0,0 +1,4 @@ +# nginx_error_messages + +This directory contains error pages for haproxy. Do not update the error pages +manually, instead look in `generate.sh` and the `template.json` file diff --git a/haproxy/errors/generate.sh b/haproxy/errors/generate.sh new file mode 100755 index 00000000000..bf9be76e991 --- /dev/null +++ b/haproxy/errors/generate.sh @@ -0,0 +1,71 @@ +#!/bin/bash +########################################################### +# +# Script to generate static error pages for haproxy +# +# To update: change messages below or the respective template file +# and rerun this script +# +########################################################### +set -eu -o pipefail +unset IFS + +DIR="$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" + +TEMPDIR="$(mktemp -d)" +trap 'rm -rf "$TEMPDIR"' EXIT + +declare -ar MESSAGES=( + "200|200 OK|Service ready|" + "400|400 Bad request|Your browser sent an invalid request|Connection: Close" + "401|401 Unauthorized|You need a valid user and password to access this content|" + "403|403 Forbidden|Request forbidden by administrative rules|" + "404|404 Not Found|The resource could not be found|" + "405|405 Method Not Allowed|A request was made of a resource using a request method not supported by that resource|" + "407|407 Unauthorized|You need a valid user and password to access this content|" + "408|408 Request Time-out|Your browser didn't send a complete request in time|Connection: Close" + "410|410 Gone|The resource is no longer available and will not be available again|" + "413|413 Payload Too Large|The request entity exceeds the maximum allowed|" + "421|421 Misdirected Request|Request sent to a non-authoritative server|" + "422|422 Unprocessable Content|The server cannot process the contained instructions|" + "425|425 Too Early|Your browser sent early data|" + "429|429 Too Many Requests|You have sent too many requests in a given amount of time|" + "500|500 Internal Server Error|An internal server error occurred|" + "501|501 Not Implemented|The server does not support the functionality required to fulfill the request|" + "502|502 Bad Gateway|The server returned an invalid or incomplete response|" + "503|503 Service Unavailable|No server is available to handle this request|" + "504|504 Gateway Time-out|The server didn't respond in time|" +) + +echo 'http-errors json' +for message in "${MESSAGES[@]}"; do + IFS='|' read -r -a message_parts <<<"$message" + status_code="${message_parts[0]}" + status_message="${message_parts[1]}" + status_reason="${message_parts[2]}" + extra_header="${message_parts[3]:-}" + + error_file="$DIR/${status_code}-json.http" + + LC_ALL="C" # So content-length/$http_body is >1 for multibyte characters + + http_body="$(sed -e "s/__MESSAGE__/$status_message/" -e "s/__REASON__/$status_reason/" <"$DIR/template.json")" + + cat <"$error_file" +HTTP/1.1 $status_message +Content-length: ${#http_body} +EOF + + [[ -n "$extra_header" ]] && echo "$extra_header" >>"$error_file" + + cat <>"$error_file" +Cache-Control: no-cache +Content-Type: application/json + +EOF + + echo -n "$http_body" >>"$error_file" + + echo " errorfile $status_code /usr/local/etc/haproxy/errors/${status_code}-json.http" + +done diff --git a/haproxy/errors/template.json b/haproxy/errors/template.json new file mode 100644 index 00000000000..947ccd1ba18 --- /dev/null +++ b/haproxy/errors/template.json @@ -0,0 +1,5 @@ +{ + "error": "__MESSAGE__", + "reason": "__REASON__", + "server": "haproxy" +} \ No newline at end of file diff --git a/haproxy/tests/Makefile b/haproxy/tests/Makefile new file mode 100644 index 00000000000..fa2bed8c238 --- /dev/null +++ b/haproxy/tests/Makefile @@ -0,0 +1,13 @@ +.PHONY: test +test: test_scripts test_with_docker_compose + +.PHONY: test_scripts +test_scripts: + bats errors_generate.bats + +.PHONY: test_with_docker_compose +test_with_docker_compose: + docker compose up --build --wait + bats with_mock.bats + docker compose down + diff --git a/haproxy/tests/compose.yml b/haproxy/tests/compose.yml new file mode 100644 index 00000000000..8ff1853acc8 --- /dev/null +++ b/haproxy/tests/compose.yml @@ -0,0 +1,34 @@ +version: "3.7" +services: + haproxy: + build: + context: ../ + ports: + - 127.0.0.1:5984:5984 + environment: + COUCHDB_SERVERS: mock-couchdb + COUCHDB_USER: someuser + COUCHDB_PASSWORD: insecure_pw + HAPROXY_IP: 0.0.0.0 + HAPROXY_PORT: 5984 + HEALTHCHECK_ADDR: haproxy-healthcheck + depends_on: + - mock-couchdb + - haproxy-healthcheck + + mock-couchdb: + image: mockserver/mockserver:5.15.0 + environment: + MOCKSERVER_SERVER_PORT: 5984 + # MOCKSERVER_LOG_LEVEL: WARN + MOCKSERVER_INITIALIZATION_JSON_PATH: /config/initializerJson.json + volumes: + - ./mock-config/initializerJson.json:/config/initializerJson.json + + haproxy-healthcheck: + build: ../../haproxy-healthcheck + environment: + COUCHDB_SERVERS: mock-couchdb + COUCHDB_USER: someuser + COUCHDB_PASSWORD: insecure_pw + diff --git a/haproxy/tests/errors_generate.bats b/haproxy/tests/errors_generate.bats new file mode 100644 index 00000000000..2d50e70adf3 --- /dev/null +++ b/haproxy/tests/errors_generate.bats @@ -0,0 +1,54 @@ +############################################################################### +# +# Tests to validate output of generate.sh +# +# If you recently made updates with error pages see readme in that folder +# +############################################################################### +setup() { + load 'test_helper/bats-support/load' # this is required by bats-assert + load 'test_helper/bats-assert/load' + + set -eu -o pipefail + + DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)" + TMP_WORK_DIR="$(mktemp -d)" + + ACTUAL_ERRORS_DIR="$DIR/../errors" + TMP_ERRORS_DIR="$TMP_WORK_DIR/errors" + + mkdir "$TMP_ERRORS_DIR" + cp "$ACTUAL_ERRORS_DIR"/{generate.sh,template.json} "$TMP_ERRORS_DIR" +} + +teardown() { + [[ -d "$TMP_WORK_DIR" ]] && rm -rf "$TMP_WORK_DIR" +} + +[[ -n "${DEBUG_BATS:-}" ]] && set -x + +@test "errors/generate.sh should be possible to run" { + run "$TMP_ERRORS_DIR/generate.sh" + assert_success +} + +@test "correct number of http files" { + "$TMP_ERRORS_DIR/generate.sh" >/dev/null + assert_equal \ + "$(find "$ACTUAL_ERRORS_DIR"/*.http | wc -l)" \ + "$(find "$TMP_ERRORS_DIR"/*.http | wc -l)" +} + +@test "file content should match for all error files " { + "$TMP_ERRORS_DIR/generate.sh" >/dev/null + + file_count=0 + for file in "$ACTUAL_ERRORS_DIR"/*.http; do + filename="$(basename "$file")" + assert_equal \ + "$(cat "$ACTUAL_ERRORS_DIR/$filename")" \ + "$(cat "$TMP_ERRORS_DIR/$filename")" + file_count=$((file_count + 1)) + done + [[ file_count -gt 0 ]] +} diff --git a/haproxy/tests/mock-config/initializerJson.json b/haproxy/tests/mock-config/initializerJson.json new file mode 100644 index 00000000000..c7e9acbb9d1 --- /dev/null +++ b/haproxy/tests/mock-config/initializerJson.json @@ -0,0 +1,36 @@ +[ + { + "httpRequest": { + "path": "/" + }, + "httpResponse": { + "body": { + "couchdb": "Welcome to mock-couchdb", + "status": "this field is not used" + } + } + }, + { + "httpRequest": { + "path": "/_membership" + }, + "httpResponse": { + "body": { + "all_nodes": [ + "mock-couchdb" + ], + "cluster_nodes": [ + "mock-couchdb" + ] + } + } + }, + { + "httpRequest": { + "path": "/error/drop" + }, + "httpError": { + "dropConnection": true + } + } +] \ No newline at end of file diff --git a/haproxy/tests/test_helper b/haproxy/tests/test_helper new file mode 120000 index 00000000000..cd72da7c705 --- /dev/null +++ b/haproxy/tests/test_helper @@ -0,0 +1 @@ +../../scripts/test/bats/test_helper \ No newline at end of file diff --git a/haproxy/tests/with_mock.bats b/haproxy/tests/with_mock.bats new file mode 100644 index 00000000000..295f6138430 --- /dev/null +++ b/haproxy/tests/with_mock.bats @@ -0,0 +1,31 @@ +setup() { + load 'test_helper/bats-support/load' # this is required by bats-assert + load 'test_helper/bats-assert/load' + + set -eu -o pipefail +} + +[[ -n "${DEBUG_BATS:-}" ]] && set -x + +@test "should respond before timeout" { + run timeout 15 bash -c "until curl -fksm5 http://127.0.0.1:5984; do sleep 0.1; done" + assert_success +} + +@test "should receive response from couchdb" { + run bash -c "curl -fksm5 http://127.0.0.1:5984/ | jq .couchdb" + assert_success + assert_output '"Welcome to mock-couchdb"' +} + +@test "should receive 404 response if path doesn't exist" { + run curl -Ifksm5 http://127.0.0.1:5984/doesnotexist + assert_failure + assert_line --partial --index 0 'HTTP/1.1 404 Not Found' +} + +@test "should return json with on connection drop" { + run bash -c "curl -ksm5 http://127.0.0.1:5984/error/drop | jq .error" + assert_success + assert_output '"502 Bad Gateway"' +} diff --git a/nginx/tests/test_helper b/nginx/tests/test_helper new file mode 120000 index 00000000000..cd72da7c705 --- /dev/null +++ b/nginx/tests/test_helper @@ -0,0 +1 @@ +../../scripts/test/bats/test_helper \ No newline at end of file diff --git a/nginx/tests/test_helper/bats-assert/load.bash b/scripts/test/bats/test_helper/bats-assert/load.bash similarity index 100% rename from nginx/tests/test_helper/bats-assert/load.bash rename to scripts/test/bats/test_helper/bats-assert/load.bash diff --git a/nginx/tests/test_helper/bats-assert/src/assert.bash b/scripts/test/bats/test_helper/bats-assert/src/assert.bash similarity index 100% rename from nginx/tests/test_helper/bats-assert/src/assert.bash rename to scripts/test/bats/test_helper/bats-assert/src/assert.bash diff --git a/nginx/tests/test_helper/bats-support/load.bash b/scripts/test/bats/test_helper/bats-support/load.bash similarity index 100% rename from nginx/tests/test_helper/bats-support/load.bash rename to scripts/test/bats/test_helper/bats-support/load.bash diff --git a/nginx/tests/test_helper/bats-support/src/error.bash b/scripts/test/bats/test_helper/bats-support/src/error.bash similarity index 100% rename from nginx/tests/test_helper/bats-support/src/error.bash rename to scripts/test/bats/test_helper/bats-support/src/error.bash diff --git a/nginx/tests/test_helper/bats-support/src/lang.bash b/scripts/test/bats/test_helper/bats-support/src/lang.bash similarity index 100% rename from nginx/tests/test_helper/bats-support/src/lang.bash rename to scripts/test/bats/test_helper/bats-support/src/lang.bash diff --git a/nginx/tests/test_helper/bats-support/src/output.bash b/scripts/test/bats/test_helper/bats-support/src/output.bash similarity index 100% rename from nginx/tests/test_helper/bats-support/src/output.bash rename to scripts/test/bats/test_helper/bats-support/src/output.bash