diff --git a/.circleci/config.yml b/.circleci/config.yml index 05be1eba6..e3c3476a7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,40 +1,105 @@ -version: 2 -jobs: - build: - machine: - image: ubuntu-1604:201903-01 - parallelism: 4 +version: 2.1 + +commands: + init-tests: + description: "Setup dokku for testing" steps: - checkout - - run: | - make ci-dependencies - - run: | - ./tests/ci/setup.sh - - run: | - echo 'export DOKKU_SKIP_CLEANUP=true' | sudo tee /home/dokku/.dokkurc/dokku_skip_cleanup - - run: | - # dokku.me now resolves to 10.0.0.2. add 10.0.0.2/24 to ens4 - sudo ip a a 10.0.0.2/24 broadcast 10.0.0.255 dev ens4 - - run: | - case $CIRCLE_NODE_INDEX in - 0) sudo -E make -e lint-ci go-tests ci-go-coverage ;; - 1) sudo -E make -e deploy-test-checks-root deploy-test-config ;; - 2) sudo -E make -e deploy-test-multi ;; - 3) sudo -E make -e deploy-test-go-fail-predeploy deploy-test-go-fail-postdeploy ;; - esac + - attach_workspace: + at: /home/circleci/project - run: + name: resolve dokku.me + command: | + # dokku.me now resolves to 10.0.0.2. add 10.0.0.2/24 to ens4 + # this is maybe eth0 on github + ifconfig + sudo ip addr add 10.0.0.2/24 broadcast 10.0.0.255 dev ens4 + - run: + name: install ci-dependencies + command: make ci-dependencies + - run: + name: setup tests + command: ./tests/ci/setup.sh + - run: + name: dokku cleanup:skip + command: echo 'export DOKKU_SKIP_CLEANUP=true' | sudo tee /home/dokku/.dokkurc/dokku_skip_cleanup + - run: + name: dokku report + command: dokku report + +executors: + default: + machine: + image: ubuntu-1604:201903-01 + working_directory: /home/circleci/project + +jobs: + build: + executor: default + steps: + - checkout + - run: + name: build package + command: ./tests/ci/setup.sh build + - persist_to_workspace: + root: /home/circleci/project + paths: + - build + docker-deploy-tests: + executor: default + steps: + - init-tests + - run: + name: test docker deploys shell: /bin/bash - command: sudo -E make -e test-ci - no_output_timeout: 60m - - run: | - if [ "${CIRCLE_NODE_INDEX}" == "0" ]; then + no_output_timeout: 20 + command: | ./tests/ci/setup.sh docker DOKKU_SSH_PORT=3022 sudo -E make -e test-ci-docker - fi + go-tests: + executor: default + parallelism: 4 + steps: + - init-tests + - run: + name: run pre-tests + command: | + case $CIRCLE_NODE_INDEX in + 0) sudo -E make -e lint-ci go-tests ci-go-coverage ;; + 1) sudo -E make -e deploy-test-checks-root deploy-test-config ;; + 2) sudo -E make -e deploy-test-multi ;; + 3) sudo -E make -e deploy-test-go-fail-predeploy deploy-test-go-fail-postdeploy ;; + esac - store_artifacts: path: ./coverage.out + test: + executor: default + parallelism: 4 + steps: + - init-tests + - run: + command: | + sudo -E make -e test-ci + no_output_timeout: 60m + shell: /bin/bash - store_artifacts: path: ./test-results destination: test-results - store_test_results: path: test-results + +workflows: + workflow: + jobs: + - build + - docker-deploy-tests: + requires: + - build + - test + - go-tests: + requires: + - build + - test: + requires: + - build + - go-tests diff --git a/common.mk b/common.mk index f4ce217db..eb26cf64c 100644 --- a/common.mk +++ b/common.mk @@ -10,7 +10,7 @@ build-in-docker: clean mkdir -p /tmp/dokku-go-build-cache docker run --rm \ -v $$PWD/../..:$(GO_REPO_ROOT) \ - -v /tmp/dokku-go-build-cache:/root/.cache/go-build \ + -v /tmp/dokku-go-build-cache:/root/.cache \ -e PLUGIN_NAME=$(PLUGIN_NAME) \ -w $(GO_REPO_ROOT)/plugins/$(PLUGIN_NAME) \ $(BUILD_IMAGE) \ diff --git a/contrib/release-dokku b/contrib/release-dokku index 6b3fce765..d52990684 100755 --- a/contrib/release-dokku +++ b/contrib/release-dokku @@ -364,9 +364,7 @@ main() { fn-extract-package "$IS_RELEASE" "dokku-${NEXT_VERSION}-1.x86_64.rpm" || log-fail "Error extracting rpm package" cp -f "build/dokku_${NEXT_VERSION}_amd64.deb" build/dokku.deb - if [[ "$RELEASE" == "build" ]]; then - fn-build-docker-image "latest" || log-fail "Error building docker image" - else + if [[ "$RELEASE" != "build" ]]; then fn-publish-package "$IS_RELEASE" "deb" "build/dokku_${NEXT_VERSION}_amd64.deb" || log-fail "Error publishing deb package" fn-publish-package "$IS_RELEASE" "rpm" "build/dokku-${NEXT_VERSION}-1.x86_64.rpm" || log-fail "Error publishing rpm package" fn-build-docker-image "$NEXT_VERSION" || log-fail "Error building docker image" diff --git a/deb.mk b/deb.mk index 1f6932877..0f9d9f4f0 100644 --- a/deb.mk +++ b/deb.mk @@ -2,7 +2,7 @@ BUILD_DIRECTORY ?= /tmp HEROKUISH_DESCRIPTION = 'Herokuish uses Docker and Buildpacks to build applications like Heroku' HEROKUISH_REPO_NAME ?= gliderlabs/herokuish -HEROKUISH_VERSION ?= 0.5.13 +HEROKUISH_VERSION ?= 0.5.14 HEROKUISH_ARCHITECTURE = amd64 HEROKUISH_PACKAGE_NAME = herokuish_$(HEROKUISH_VERSION)_$(HEROKUISH_ARCHITECTURE).deb @@ -80,7 +80,7 @@ deb-herokuish: --version $(HEROKUISH_VERSION) \ --architecture $(HEROKUISH_ARCHITECTURE) \ --package $(BUILD_DIRECTORY)/$(HEROKUISH_PACKAGE_NAME) \ - --deb-pre-depends 'docker-engine-cs (>= 1.9.1) | docker-engine (>= 1.9.1) | docker-ce | docker-ee' \ + --deb-pre-depends 'docker-engine-cs (>= 1.13.0) | docker-engine (>= 1.13.0) | docker-io (>= 1.13.0) | docker.io (>= 1.13.0) | docker-ce (>= 1.13.0) | docker-ee (>= 1.13.0) | moby-engine' \ --deb-pre-depends sudo \ --after-install /tmp/tmp/post-install \ --url "https://github.com/$(HEROKUISH_REPO_NAME)" \ diff --git a/tests.mk b/tests.mk index b59fb72f0..caceecc90 100644 --- a/tests.mk +++ b/tests.mk @@ -55,7 +55,9 @@ endif mkdir -p /root/.ssh rm -f /root/.ssh/dokku_test_rsa* echo -e "y\n" | ssh-keygen -f /root/.ssh/dokku_test_rsa -t rsa -N '' - chmod 600 /root/.ssh/dokku_test_rsa* + chmod 700 /root/.ssh + chmod 600 /root/.ssh/dokku_test_rsa + chmod 644 /root/.ssh/dokku_test_rsa.pub @echo "-----> Setting up ssh config..." ifneq ($(shell ls /root/.ssh/config >/dev/null 2>&1 ; echo $$?),0) @@ -78,8 +80,11 @@ endif endif @echo "-----> Installing SSH public key..." + echo "" > /home/dokku/.ssh/authorized_keys sudo sshcommand acl-remove dokku test cat /root/.ssh/dokku_test_rsa.pub | sudo sshcommand acl-add dokku test + chmod 700 /home/dokku/.ssh + chmod 600 /home/dokku/.ssh/authorized_keys ifeq ($(shell grep dokku.me /home/dokku/VHOST 2>/dev/null),) @echo "-----> Setting default VHOST to dokku.me..." @@ -100,7 +105,9 @@ endif prime-ssh-known-hosts: @echo "-----> Intitial SSH connection to populate known_hosts..." + @echo "=====> SSH dokku.me" ssh -o StrictHostKeyChecking=no dokku@dokku.me help >/dev/null + @echo "=====> SSH 127.0.0.1" ssh -o StrictHostKeyChecking=no dokku@127.0.0.1 help >/dev/null lint-setup: diff --git a/tests/apps/dockerfile-dokku-scale/Dockerfile b/tests/apps/dockerfile-dokku-scale/Dockerfile index fa82185d5..eee648649 100644 --- a/tests/apps/dockerfile-dokku-scale/Dockerfile +++ b/tests/apps/dockerfile-dokku-scale/Dockerfile @@ -1,4 +1,6 @@ -FROM node:4 +FROM node:4-alpine + +RUN apk add --no-cache bash EXPOSE 3001/udp EXPOSE 3000/tcp diff --git a/tests/apps/dockerfile-noexpose/Dockerfile b/tests/apps/dockerfile-noexpose/Dockerfile index 86399657a..61aa17519 100644 --- a/tests/apps/dockerfile-noexpose/Dockerfile +++ b/tests/apps/dockerfile-noexpose/Dockerfile @@ -1,4 +1,6 @@ -FROM node:4 +FROM node:4-alpine + +RUN apk add --no-cache bash COPY . /app WORKDIR /app diff --git a/tests/apps/dockerfile-procfile-bad/Dockerfile b/tests/apps/dockerfile-procfile-bad/Dockerfile index fa82185d5..eee648649 100644 --- a/tests/apps/dockerfile-procfile-bad/Dockerfile +++ b/tests/apps/dockerfile-procfile-bad/Dockerfile @@ -1,4 +1,6 @@ -FROM node:4 +FROM node:4-alpine + +RUN apk add --no-cache bash EXPOSE 3001/udp EXPOSE 3000/tcp diff --git a/tests/apps/dockerfile-procfile/Dockerfile b/tests/apps/dockerfile-procfile/Dockerfile index fa82185d5..eee648649 100644 --- a/tests/apps/dockerfile-procfile/Dockerfile +++ b/tests/apps/dockerfile-procfile/Dockerfile @@ -1,4 +1,6 @@ -FROM node:4 +FROM node:4-alpine + +RUN apk add --no-cache bash EXPOSE 3001/udp EXPOSE 3000/tcp diff --git a/tests/apps/dockerfile/Dockerfile b/tests/apps/dockerfile/Dockerfile index 5b7dfd4fc..eef0c10e8 100644 --- a/tests/apps/dockerfile/Dockerfile +++ b/tests/apps/dockerfile/Dockerfile @@ -1,4 +1,6 @@ -FROM node:4 +FROM node:4-alpine + +RUN apk add --no-cache bash EXPOSE 3001/udp EXPOSE 3000/tcp diff --git a/tests/apps/python/.buildpacks b/tests/apps/python/.buildpacks new file mode 100644 index 000000000..b86e298c6 --- /dev/null +++ b/tests/apps/python/.buildpacks @@ -0,0 +1 @@ +https://github.com/dokku/buildpack-null.git diff --git a/tests/apps/python/CHECKS b/tests/apps/python/CHECKS new file mode 100644 index 000000000..52a9225d1 --- /dev/null +++ b/tests/apps/python/CHECKS @@ -0,0 +1,5 @@ +WAIT=2 # wait 2 seconds +TIMEOUT=5 # set timeout to 5 seconds +ATTEMPTS=2 # try 2 times + +/ python/http.server diff --git a/tests/apps/python/Procfile b/tests/apps/python/Procfile new file mode 100644 index 000000000..def474954 --- /dev/null +++ b/tests/apps/python/Procfile @@ -0,0 +1,54 @@ +############################### +# DEVELOPMENT # +############################### + +# Procfile for development using the new threaded worker (scheduler, twitter stream and delayed job) +cron: python3 worker.py +web: python3 web.py # testing inline comment +worker: python3 worker.py +custom: echo -n +release: touch /app/release.test + + +# Old version with separate processes (use this if you have issues with the threaded version) +# web: bundle exec rails server +# schedule: bundle exec rails runner bin/schedule.rb +# twitter: bundle exec rails runner bin/twitter_stream.rb +# dj: bundle exec script/delayed_job run + +############################### +# PRODUCTION # +############################### + +# You need to copy or link config/unicorn.rb.example to config/unicorn.rb for both production versions. +# Have a look at the deployment guides, if you want to set up huginn on your server: +# https://github.com/cantino/huginn/doc + +# Using the threaded worker (consumes less RAM but can run slower) +# web: bundle exec unicorn -c config/unicorn.rb +# jobs: bundle exec rails runner bin/threaded.rb + +# Old version with separate processes (use this if you have issues with the threaded version) +# web: bundle exec unicorn -c config/unicorn.rb +# schedule: bundle exec rails runner bin/schedule.rb +# twitter: bundle exec rails runner bin/twitter_stream.rb +# dj: bundle exec script/delayed_job run + +############################### +# Multiple DelayedJob workers # +############################### +# Per default Huginn can just run one agent at a time. Using a lot of agents or calling slow +# external services frequently might require more DelayedJob workers (an indicator for this is +# a backlog in your 'Job Management' page). +# Every uncommented line starts an additional DelayedJob worker. This works for development, production +# and for the threaded and separate worker processes. Keep in mind one worker needs about 300MB of RAM. +# +#dj2: bundle exec script/delayed_job -i 2 run +#dj3: bundle exec script/delayed_job -i 3 run +#dj4: bundle exec script/delayed_job -i 4 run +#dj5: bundle exec script/delayed_job -i 5 run +#dj6: bundle exec script/delayed_job -i 6 run +#dj7: bundle exec script/delayed_job -i 7 run +#dj8: bundle exec script/delayed_job -i 8 run +#dj9: bundle exec script/delayed_job -i 9 run +#dj10: bundle exec script/delayed_job -i 10 run diff --git a/tests/apps/python/app.json b/tests/apps/python/app.json new file mode 100644 index 000000000..0dbdea3ec --- /dev/null +++ b/tests/apps/python/app.json @@ -0,0 +1,8 @@ +{ + "scripts": { + "dokku": { + "predeploy": "touch /app/predeploy.test", + "postdeploy": "touch /app/postdeploy.test" + } + } +} diff --git a/tests/apps/python/check_deploy b/tests/apps/python/check_deploy new file mode 100644 index 000000000..db53f009f --- /dev/null +++ b/tests/apps/python/check_deploy @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -e +output="$(curl -s -S "$1")" +echo "$output" +test "$output" == "python/http.server" diff --git a/tests/apps/python/null b/tests/apps/python/null new file mode 100644 index 000000000..e69de29bb diff --git a/tests/apps/python/web.py b/tests/apps/python/web.py new file mode 100644 index 000000000..b3e8ef728 --- /dev/null +++ b/tests/apps/python/web.py @@ -0,0 +1,17 @@ +import http.server +import os + + +class GetHandler(http.server.BaseHTTPRequestHandler): + def do_GET(self): + self.send_response(200) + self.send_header("Content-Type", "text/plain; charset=utf-8") + self.end_headers() + self.wfile.write("python/http.server".encode("utf-8")) + + +if __name__ == "__main__": + port = int(os.getenv("PORT", 5000)) + server = http.server.HTTPServer(("0.0.0.0", port), GetHandler) + print("Listening on port {0}".format(port)) + server.serve_forever() diff --git a/tests/apps/python/worker.py b/tests/apps/python/worker.py new file mode 100644 index 000000000..30fd58b59 --- /dev/null +++ b/tests/apps/python/worker.py @@ -0,0 +1,11 @@ +import time + + +def main(): + print("sleeping for 60 seconds") + while True: + time.sleep(60) + + +if __name__ == "__main__": + main() diff --git a/tests/ci/setup.sh b/tests/ci/setup.sh index 7eff42a7c..97f619636 100755 --- a/tests/ci/setup.sh +++ b/tests/ci/setup.sh @@ -40,6 +40,11 @@ install_dependencies() { } build_dokku() { + if [[ "$FROM_SOURCE" == "true" ]]; then + sudo -E CI=true make -e install + return + fi + echo "=====> build_dokku on CIRCLE_NODE_INDEX: $CIRCLE_NODE_INDEX" "${ROOT_DIR}/contrib/release-dokku" build } @@ -47,13 +52,10 @@ build_dokku() { install_dokku() { echo "=====> install_dokku on CIRCLE_NODE_INDEX: $CIRCLE_NODE_INDEX" - if [[ "$FROM_SOURCE" == "true" ]]; then - sudo -E CI=true make -e install - return + if [[ ! -f "${ROOT_DIR}/build/deb-filename" ]]; then + build_dokku fi - build_dokku - echo "dokku dokku/hostname string dokku.me" | sudo debconf-set-selections echo "dokku dokku/key_file string /root/.ssh/id_rsa.pub" | sudo debconf-set-selections echo "dokku dokku/nginx_enable boolean true" | sudo debconf-set-selections @@ -102,25 +104,37 @@ check_container() { done } -# shellcheck disable=SC2120 -setup_circle() { +create_package() { echo "=====> setup_circle on CIRCLE_NODE_INDEX: $CIRCLE_NODE_INDEX" sudo -E CI=true make -e sshcommand # need to add the dokku user to the docker group sudo usermod -G docker dokku [[ "$1" == "buildstack" ]] && BUILD_STACK=true make -e stack + install_dependencies + build_dokku +} + +# shellcheck disable=SC2120 +setup_circle() { install_dependencies install_dokku sudo -E make -e setup-deploy-tests lsb_release -a # setup .dokkurc + + getent passwd | cut -d: -f1 | sort + sudo -E mkdir -p /home/dokku/.dokkurc - sudo -E chown dokku:ubuntu /home/dokku/.dokkurc + if [[ -n "$GITHUB_ACTIONS" ]]; then + sudo -E chown dokku:dokku /home/dokku/.dokkurc + else + sudo -E chown dokku:ubuntu /home/dokku/.dokkurc + fi sudo -E chmod 775 /home/dokku/.dokkurc - # pull node:4 image for testing - sudo docker pull node:4 + # pull node:4-alpine image for testing + sudo docker pull node:4-alpine } case "$1" in @@ -129,6 +143,11 @@ case "$1" in build_dokku_docker_image run_dokku_container ;; + build) + # shellcheck disable=SC2119 + create_package + exit $? + ;; *) # shellcheck disable=SC2119 setup_circle diff --git a/tests/unit/10_ps-dockerfile.bats b/tests/unit/10_ps-dockerfile.bats deleted file mode 100644 index a32a296b4..000000000 --- a/tests/unit/10_ps-dockerfile.bats +++ /dev/null @@ -1,270 +0,0 @@ -#!/usr/bin/env bats - -load test_helper - -setup() { - global_setup - create_app -} - -teardown() { - destroy_app - global_teardown -} - -@test "(ps) dockerfile" { - deploy_app dockerfile - run /bin/bash -c "dokku ps:stop $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do - run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" - echo "output: $output" - echo "status: $status" - assert_failure - done - - run /bin/bash -c "dokku ps:start $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do - run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" - echo "output: $output" - echo "status: $status" - assert_success - done - - run /bin/bash -c "dokku ps:restart $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do - run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" - echo "output: $output" - echo "status: $status" - assert_success - done - - run /bin/bash -c "dokku ps:rebuild $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do - run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" - echo "output: $output" - echo "status: $status" - assert_success - done -} - -@test "(ps:scale) dockerfile non-existent process" { - run /bin/bash -c "dokku ps:scale $TEST_APP non-existent=2" - echo "output: $output" - echo "status: $status" - assert_success - - destroy_app - create_app - deploy_app dockerfile-procfile - run /bin/bash -c "dokku ps:scale $TEST_APP non-existent=2" - echo "output: $output" - echo "status: $status" - assert_failure -} - -@test "(ps:scale) dockerfile" { - run /bin/bash -c "dokku ps:scale $TEST_APP web=2" - echo "output: $output" - echo "status: $status" - assert_success - - deploy_app dockerfile - CIDS="" - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do - CIDS+=$(< $CID_FILE) - CIDS+=" " - done - CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 2" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku ps:scale $TEST_APP web=1" - echo "output: $output" - echo "status: $status" - assert_success - CIDS="" - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do - CIDS+=$(< $CID_FILE) - CIDS+=" " - done - CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 1" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku ps:scale $TEST_APP web=0" - echo "output: $output" - echo "status: $status" - assert_success - CIDS="" - shopt -s nullglob - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do - CIDS+=$(< $CID_FILE) - CIDS+=" " - done - run /bin/bash -c "[[ -z \"$CIDS\" ]]" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(ps:scale) dockerfile dokku-scale" { - run /bin/bash -c "dokku ps:scale $TEST_APP web=2" - echo "output: $output" - echo "status: $status" - assert_success - - deploy_app dockerfile-dokku-scale - CIDS="" - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do - CIDS+=$(< $CID_FILE) - CIDS+=" " - done - CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 1" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku ps:scale $TEST_APP web=1" - echo "output: $output" - echo "status: $status" - assert_failure - - run /bin/bash -c "dokku ps:report $TEST_APP --ps-can-scale" - echo "output: $output" - echo "status: $status" - assert_output "false" -} - -@test "(ps) dockerfile with procfile" { - deploy_app dockerfile-procfile - run /bin/bash -c "dokku ps:stop $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do - run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" - echo "output: $output" - echo "status: $status" - assert_failure - done - - run /bin/bash -c "dokku ps:start $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do - run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" - echo "output: $output" - echo "status: $status" - assert_success - done - - run /bin/bash -c "dokku ps:restart $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do - run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" - echo "output: $output" - echo "status: $status" - assert_success - done - - run /bin/bash -c "dokku ps:rebuild $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do - run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" - echo "output: $output" - echo "status: $status" - assert_success - done -} - -@test "(ps) dockerfile with bad procfile" { - run deploy_app dockerfile-procfile-bad - echo "output: $output" - echo "status: $status" - assert_failure - - run create_app - assert_success -} - -@test "(ps:scale) dockerfile with procfile" { - run /bin/bash -c "dokku ps:scale $TEST_APP web=2 worker=2" - echo "output: $output" - echo "status: $status" - assert_success - - deploy_app dockerfile-procfile - for PROC_TYPE in web worker; do - run /bin/bash -c "docker ps --format '{{.ID}} {{.Command}}' --no-trunc" - echo "output: $output" - echo "status: $status" - assert_success - goodlines="" - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do - cid=$(< $CID_FILE) - assert_output_contains "$cid" - goodlines+=$(echo "$output" | grep "$cid") - done - output="$goodlines" - assert_output_contains "node ${PROC_TYPE}.js" 2 - done - - run /bin/bash -c "dokku ps:scale $TEST_APP web=1 worker=1" - echo "output: $output" - echo "status: $status" - assert_success - for PROC_TYPE in web worker; do - run /bin/bash -c "docker ps --format '{{.ID}} {{.Command}}' --no-trunc" - echo "output: $output" - echo "status: $status" - assert_success - goodlines="" - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do - cid=$(< $CID_FILE) - assert_output_contains "$cid" - goodlines+=$(echo "$output" | grep "$cid") - done - output="$goodlines" - assert_output_contains "node ${PROC_TYPE}.js" - done - - run /bin/bash -c "dokku ps:scale $TEST_APP web=0 worker=0" - echo "output: $output" - echo "status: $status" - assert_success - for PROC_TYPE in web worker; do - CIDS="" - shopt -s nullglob - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do - CIDS+=$(< $CID_FILE) - CIDS+=" " - done - shopt -u nullglob - run /bin/bash -c "[[ -z \"$CIDS\" ]]" - echo "output: $output" - echo "status: $status" - assert_success - done -} diff --git a/tests/unit/20_nginx-vhosts_1.bats b/tests/unit/20_nginx-vhosts_1.bats deleted file mode 100644 index 5c45c2411..000000000 --- a/tests/unit/20_nginx-vhosts_1.bats +++ /dev/null @@ -1,168 +0,0 @@ -#!/usr/bin/env bats - -load test_helper -source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" - -setup() { - global_setup - [[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak" - [[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak" -} - -teardown() { - detach_delete_network - destroy_app - [[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST" - [[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME" - global_teardown -} - -@test "(nginx) nginx:help" { - run /bin/bash -c "dokku nginx" - echo "output: $output" - echo "status: $status" - assert_output_contains "Manage the nginx proxy" - help_output="$output" - - run /bin/bash -c "dokku nginx:help" - echo "output: $output" - echo "status: $status" - assert_output_contains "Manage the nginx proxy" - assert_output "$help_output" -} - -@test "(nginx-vhosts) nginx:build-config (domains:disable/enable)" { - deploy_app - dokku domains:disable $TEST_APP - - HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME") - check_urls http://${HOSTNAME}:[0-9]+ - - URLS=$(dokku --quiet urls "$TEST_APP") - for URL in $URLS; do - assert_http_success $URL - done - - dokku domains:enable $TEST_APP - check_urls http://${TEST_APP}.dokku.me - assert_http_success http://${TEST_APP}.dokku.me -} - -@test "(nginx-vhosts) nginx:build-config (domains:add pre deploy)" { - create_app - run /bin/bash -c "dokku domains:add $TEST_APP www.test.app.dokku.me" - echo "output: $output" - echo "status: $status" - assert_success - - deploy_app - sleep 5 # wait for nginx to reload - - check_urls http://www.test.app.dokku.me - assert_http_success http://www.test.app.dokku.me -} - -@test "(nginx-vhosts) nginx:build-config (with global VHOST)" { - echo "dokku.me" > "$DOKKU_ROOT/VHOST" - deploy_app - - check_urls http://${TEST_APP}.dokku.me - assert_http_success http://${TEST_APP}.dokku.me -} - -@test "(nginx-vhosts) nginx:build-config (without global VHOST but real HOSTNAME)" { - rm "$DOKKU_ROOT/VHOST" - echo "${TEST_APP}.dokku.me" > "$DOKKU_ROOT/HOSTNAME" - deploy_app - - HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME") - check_urls http://${HOSTNAME}:[0-9]+ - - URLS=$(dokku --quiet urls "$TEST_APP") - for URL in $URLS; do - assert_http_success $URL - done -} - -@test "(nginx-vhosts) nginx:build-config (without global VHOST and IPv4 address set as HOSTNAME)" { - rm "$DOKKU_ROOT/VHOST" - echo "127.0.0.1" > "$DOKKU_ROOT/HOSTNAME" - deploy_app - - HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME") - check_urls http://${HOSTNAME}:[0-9]+ - - URLS=$(dokku --quiet urls "$TEST_APP") - for URL in $URLS; do - assert_http_success $URL - done -} - -@test "(nginx-vhosts) nginx:build-config (without global VHOST and IPv6 address set as HOSTNAME)" { - rm "$DOKKU_ROOT/VHOST" - echo "fda5:c7db:a520:bb6d::aabb:ccdd:eeff" > "$DOKKU_ROOT/HOSTNAME" - deploy_app - - HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME") - check_urls http://${HOSTNAME}:[0-9]+ -} - -@test "(nginx-vhosts) nginx:build-config (without global VHOST and domains:add pre deploy)" { - rm "$DOKKU_ROOT/VHOST" - create_app - add_domain "www.test.app.dokku.me" - deploy_app - assert_nonssl_domain "www.test.app.dokku.me" -} - -@test "(nginx-vhosts) nginx:build-config (without global VHOST and domains:add post deploy)" { - rm "$DOKKU_ROOT/VHOST" - deploy_app - add_domain "www.test.app.dokku.me" - check_urls http://www.test.app.dokku.me - assert_http_success http://www.test.app.dokku.me -} - -@test "(nginx-vhosts) nginx:build-config (xip.io style hostnames)" { - echo "127.0.0.1.xip.io.dokku.me" > "$DOKKU_ROOT/VHOST" - deploy_app - - check_urls http://${TEST_APP}.127.0.0.1.xip.io.dokku.me - assert_http_success http://${TEST_APP}.127.0.0.1.xip.io.dokku.me -} - -@test "(nginx-vhosts) nginx:build-config (dockerfile expose)" { - deploy_app dockerfile - - add_domain "www.test.app.dokku.me" - check_urls http://${TEST_APP}.dokku.me:3000 - check_urls http://${TEST_APP}.dokku.me:3003 - check_urls http://www.test.app.dokku.me:3000 - check_urls http://www.test.app.dokku.me:3003 - assert_http_success http://${TEST_APP}.dokku.me:3000 - assert_http_success http://${TEST_APP}.dokku.me:3003 - assert_http_success http://www.test.app.dokku.me:3000 - assert_http_success http://www.test.app.dokku.me:3003 - -} - -@test "(nginx-vhosts) nginx:build-config (multiple networks)" { - deploy_app - - create_attach_network - run /bin/bash -c "dokku nginx:build-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(nginx-vhosts) nginx:build-config (global DOKKU_PROXY_PORT)" { - local GLOBAL_PORT=30999 - run /bin/bash -c "dokku config:set --global DOKKU_PROXY_PORT=${GLOBAL_PORT}" - - deploy_app - check_urls http://${TEST_APP}.dokku.me:${GLOBAL_PORT} - assert_http_success http://${TEST_APP}.dokku.me:${GLOBAL_PORT} - - run /bin/bash -c "dokku config:unset --global DOKKU_PROXY_PORT" -} diff --git a/tests/unit/50_init_1.bats b/tests/unit/50_init_1.bats deleted file mode 100644 index 98581d63b..000000000 --- a/tests/unit/50_init_1.bats +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bats - -load test_helper - -setup() { - global_setup - create_app -} - -teardown() { - destroy_app - global_teardown -} - -@test "(init) buildpack" { - source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" - local APP="zombies-buildpack" - deploy_app "$APP" - local CIDS=$(get_app_container_ids "$APP") - - run "$DOCKER_BIN" container top "$CIDS" - echo "output: $output" - assert_output_contains "" "0" -} diff --git a/tests/unit/50_init_2.bats b/tests/unit/50_init_2.bats deleted file mode 100644 index c0b5d459a..000000000 --- a/tests/unit/50_init_2.bats +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bats - -load test_helper - -setup() { - global_setup - create_app -} - -teardown() { - destroy_app - global_teardown -} - -@test "(init) dockerfile no tini" { - source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" - local APP="zombies-dockerfile-no-tini" - deploy_app "$APP" - local CIDS=$(get_app_container_ids "$APP") - - run "$DOCKER_BIN" container top "$CIDS" - echo "output: $output" - assert_output_contains "" "0" -} diff --git a/tests/unit/50_init_3.bats b/tests/unit/50_init_3.bats deleted file mode 100644 index 77c354b1b..000000000 --- a/tests/unit/50_init_3.bats +++ /dev/null @@ -1,24 +0,0 @@ -#!/usr/bin/env bats - -load test_helper - -setup() { - global_setup - create_app -} - -teardown() { - destroy_app - global_teardown -} - -@test "(init) dockerfile with tini" { - source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" - local APP="zombies-dockerfile-tini" - deploy_app "$APP" - local CIDS=$(get_app_container_ids "$APP") - - run "$DOCKER_BIN" container top "$CIDS" - echo "output: $output" - assert_output_contains "" "0" -} diff --git a/tests/unit/40_app-json.bats b/tests/unit/app-json.bats similarity index 100% rename from tests/unit/40_app-json.bats rename to tests/unit/app-json.bats diff --git a/tests/unit/10_apps.bats b/tests/unit/apps_1.bats similarity index 58% rename from tests/unit/10_apps.bats rename to tests/unit/apps_1.bats index 1a19699db..f09753bca 100644 --- a/tests/unit/10_apps.bats +++ b/tests/unit/apps_1.bats @@ -228,170 +228,6 @@ teardown() { assert_success } -@test "(apps) apps:clone" { - deploy_app - run /bin/bash -c "dokku apps:clone $TEST_APP great-test-name" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku apps:list | grep $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url great-test-name` | grep 404" - echo "output: $output" - echo "status: $status" - assert_output "" - run /bin/bash -c "dokku --force apps:destroy great-test-name" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(apps) apps:clone (no app)" { - run /bin/bash -c "dokku apps:create $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku buildpacks:add $TEST_APP https://github.com/heroku/heroku-buildpack-ruby.git" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku git:set $TEST_APP deploy-branch SOME_BRANCH_NAME" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku network:set $TEST_APP attach-post-create test-network" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku nginx:set $TEST_APP bind-address-ipv4 127.0.0.1" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku resource:limit --memory 100 $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku scheduler-docker-local:set $TEST_APP disable-chown true" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku apps:clone $TEST_APP great-test-name" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku apps:list | grep $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku buildpacks:report great-test-name --buildpacks-list" - echo "output: $output" - echo "status: $status" - assert_success - assert_output "https://github.com/heroku/heroku-buildpack-ruby.git" - run /bin/bash -c "dokku git:report great-test-name --git-deploy-branch" - echo "output: $output" - echo "status: $status" - assert_success - assert_output "SOME_BRANCH_NAME" - run /bin/bash -c "dokku network:report great-test-name --network-attach-post-create" - echo "output: $output" - echo "status: $status" - assert_success - assert_output "test-network" - run /bin/bash -c "dokku nginx:report great-test-name --nginx-bind-address-ipv4" - echo "output: $output" - echo "status: $status" - assert_success - assert_output "127.0.0.1" - run /bin/bash -c "dokku resource:report great-test-name --resource-_default_.limit.memory" - echo "output: $output" - echo "status: $status" - assert_success - assert_output "100" - run /bin/bash -c "dokku scheduler-docker-local:report great-test-name --scheduler-docker-local-disable-chown" - echo "output: $output" - echo "status: $status" - assert_success - assert_output "true" - - run /bin/bash -c "dokku --force apps:destroy great-test-name" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(apps) apps:clone ssl-app" { - run /bin/bash -c "dokku config:set --no-restart $TEST_APP DOKKU_PROXY_PORT_MAP=https:443:5000 DOKKU_PROXY_SSL_PORT=443" - deploy_app - run /bin/bash -c "dokku apps:clone $TEST_APP app-without-ssl" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku --quiet proxy:ports app-without-ssl | xargs" - echo "output: $output" - echo "status: $status" - assert_output "http 80 5000" - run /bin/bash -c "dokku config:get app-without-ssl DOKKU_PROXY_SSL_PORT" - echo "output: $output" - echo "status: $status" - assert_output "" - run /bin/bash -c "dokku --force apps:destroy app-without-ssl" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(apps) apps:clone --skip-deploy" { - deploy_app - run /bin/bash -c "dokku apps:clone --skip-deploy $TEST_APP great-test-name" - echo "output: $output" - echo "status: $status" - assert_success - run [ -d /home/dokku/great-test-name/tls ] - assert_failure - run [ -f /home/dokku/great-test-name/URLS ] - assert_failure - run [ -f /home/dokku/great-test-name/VHOST ] - assert_failure - run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url $TEST_APP` | grep 200" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url great-test-name` | grep 404" - echo "output: $output" - echo "status: $status" - assert_failure - run /bin/bash -c "dokku --force apps:destroy great-test-name" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url $TEST_APP` | grep 200" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(apps) apps:clone --ignore-existing" { - deploy_app - run /bin/bash -c "dokku apps:create great-test-name" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku apps:clone --ignore-existing $TEST_APP great-test-name" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "dokku --force apps:destroy great-test-name" - echo "output: $output" - echo "status: $status" - assert_success -} - @test "(apps) apps:exists" { run /bin/bash -c "dokku apps:exists $TEST_APP" echo "output: $output" diff --git a/tests/unit/apps_2.bats b/tests/unit/apps_2.bats new file mode 100644 index 000000000..71b846d4c --- /dev/null +++ b/tests/unit/apps_2.bats @@ -0,0 +1,175 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup +} + +teardown() { + global_teardown +} + +@test "(apps) apps:clone" { + deploy_app + run /bin/bash -c "dokku apps:clone $TEST_APP great-test-name" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku apps:list | grep $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url great-test-name` | grep 404" + echo "output: $output" + echo "status: $status" + assert_output "" + run /bin/bash -c "dokku --force apps:destroy great-test-name" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(apps) apps:clone (no app)" { + run /bin/bash -c "dokku apps:create $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku buildpacks:add $TEST_APP https://github.com/heroku/heroku-buildpack-ruby.git" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku git:set $TEST_APP deploy-branch SOME_BRANCH_NAME" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku network:set $TEST_APP attach-post-create test-network" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku nginx:set $TEST_APP bind-address-ipv4 127.0.0.1" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku resource:limit --memory 100 $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku scheduler-docker-local:set $TEST_APP disable-chown true" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku apps:clone $TEST_APP great-test-name" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku apps:list | grep $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku buildpacks:report great-test-name --buildpacks-list" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "https://github.com/heroku/heroku-buildpack-ruby.git" + run /bin/bash -c "dokku git:report great-test-name --git-deploy-branch" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "SOME_BRANCH_NAME" + run /bin/bash -c "dokku network:report great-test-name --network-attach-post-create" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "test-network" + run /bin/bash -c "dokku nginx:report great-test-name --nginx-bind-address-ipv4" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "127.0.0.1" + run /bin/bash -c "dokku resource:report great-test-name --resource-_default_.limit.memory" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "100" + run /bin/bash -c "dokku scheduler-docker-local:report great-test-name --scheduler-docker-local-disable-chown" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "true" + + run /bin/bash -c "dokku --force apps:destroy great-test-name" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(apps) apps:clone ssl-app" { + run /bin/bash -c "dokku config:set --no-restart $TEST_APP DOKKU_PROXY_PORT_MAP=https:443:5000 DOKKU_PROXY_SSL_PORT=443" + deploy_app + run /bin/bash -c "dokku apps:clone $TEST_APP app-without-ssl" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku --quiet proxy:ports app-without-ssl | xargs" + echo "output: $output" + echo "status: $status" + assert_output "http 80 5000" + run /bin/bash -c "dokku config:get app-without-ssl DOKKU_PROXY_SSL_PORT" + echo "output: $output" + echo "status: $status" + assert_output "" + run /bin/bash -c "dokku --force apps:destroy app-without-ssl" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(apps) apps:clone --skip-deploy" { + deploy_app + run /bin/bash -c "dokku apps:clone --skip-deploy $TEST_APP great-test-name" + echo "output: $output" + echo "status: $status" + assert_success + run [ -d /home/dokku/great-test-name/tls ] + assert_failure + run [ -f /home/dokku/great-test-name/URLS ] + assert_failure + run [ -f /home/dokku/great-test-name/VHOST ] + assert_failure + run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url $TEST_APP` | grep 200" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url great-test-name` | grep 404" + echo "output: $output" + echo "status: $status" + assert_failure + run /bin/bash -c "dokku --force apps:destroy great-test-name" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "curl --silent --write-out '%{http_code}\n' `dokku url $TEST_APP` | grep 200" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(apps) apps:clone --ignore-existing" { + deploy_app + run /bin/bash -c "dokku apps:create great-test-name" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku apps:clone --ignore-existing $TEST_APP great-test-name" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku --force apps:destroy great-test-name" + echo "output: $output" + echo "status: $status" + assert_success +} diff --git a/tests/unit/20_build-env.bats b/tests/unit/build-env.bats similarity index 100% rename from tests/unit/20_build-env.bats rename to tests/unit/build-env.bats diff --git a/tests/unit/30_buildpacks.bats b/tests/unit/buildpacks.bats similarity index 99% rename from tests/unit/30_buildpacks.bats rename to tests/unit/buildpacks.bats index c45794699..f5e374c81 100644 --- a/tests/unit/30_buildpacks.bats +++ b/tests/unit/buildpacks.bats @@ -268,7 +268,7 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "dokku buildpacks:set $TEST_APP https://github.com/heroku/heroku-buildpack-nodejs" + run /bin/bash -c "dokku buildpacks:set $TEST_APP https://github.com/dokku/buildpack-null" echo "output: $output" echo "status: $status" assert_success @@ -286,7 +286,7 @@ teardown() { run /bin/bash -c "dokku ps:rebuild $TEST_APP" echo "output: $output" echo "status: $status" - assert_success + assert_failure run destroy_app echo "output: $output" diff --git a/tests/unit/10_certs.bats b/tests/unit/certs.bats similarity index 100% rename from tests/unit/10_certs.bats rename to tests/unit/certs.bats diff --git a/tests/unit/10_checks.bats b/tests/unit/checks.bats similarity index 100% rename from tests/unit/10_checks.bats rename to tests/unit/checks.bats diff --git a/tests/unit/30_client.bats b/tests/unit/client.bats similarity index 100% rename from tests/unit/30_client.bats rename to tests/unit/client.bats diff --git a/tests/unit/30_config-oddities.bats b/tests/unit/config-oddities.bats similarity index 100% rename from tests/unit/30_config-oddities.bats rename to tests/unit/config-oddities.bats diff --git a/tests/unit/20_config.bats b/tests/unit/config.bats similarity index 100% rename from tests/unit/20_config.bats rename to tests/unit/config.bats diff --git a/tests/unit/30_core_1.bats b/tests/unit/core_1.bats similarity index 51% rename from tests/unit/30_core_1.bats rename to tests/unit/core_1.bats index fe488c838..fdaa43765 100644 --- a/tests/unit/30_core_1.bats +++ b/tests/unit/core_1.bats @@ -50,109 +50,6 @@ teardown() { docker rm $RANDOM_RUN_CID } -@test "(core) run (with DOKKU_RM_CONTAINER/--rm-container)" { - deploy_app - - run /bin/bash -c "dokku --rm-container run $TEST_APP echo $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" - echo "output: $output" - echo "status: $status" - assert_failure - - run /bin/bash -c "dokku config:set --no-restart $TEST_APP DOKKU_RM_CONTAINER=1" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku --rm-container run $TEST_APP echo $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" - echo "output: $output" - echo "status: $status" - assert_failure - - run /bin/bash -c "dokku config:unset --no-restart $TEST_APP DOKKU_RM_CONTAINER" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku config:set --global DOKKU_RM_CONTAINER=1" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku --rm-container run $TEST_APP echo $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" - echo "output: $output" - echo "status: $status" - assert_failure - - run /bin/bash -c "dokku config:unset --global DOKKU_RM_CONTAINER" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(core) run (detached)" { - deploy_app - - RANDOM_RUN_CID="$(dokku --label=com.dokku.test-label=value --detach run $TEST_APP sleep 300)" - run /bin/bash -c "docker inspect -f '{{ .State.Status }}' $RANDOM_RUN_CID" - echo "output: $output" - echo "status: $status" - assert_output "running" - - run /bin/bash -c "docker inspect $RANDOM_RUN_CID --format '{{ index .Config.Labels \"com.dokku.test-label\" }}'" - echo "output: $output" - echo "status: $status" - assert_output "value" - - run /bin/bash -c "docker stop $RANDOM_RUN_CID" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku cleanup" - echo "output: $output" - echo "status: $status" - assert_success - sleep 5 # wait for dokku cleanup to happen in the background -} - -@test "(core) run (with tty)" { - deploy_app - run /bin/bash -c "dokku run $TEST_APP ls /app/package.json" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(core) run (without tty)" { - deploy_app - run /bin/bash -c ": |dokku run $TEST_APP ls /app/package.json" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(core) run command from Procfile" { - deploy_app - run /bin/bash -c "dokku run $TEST_APP custom 'hi dokku' | tail -n 1" - echo "output: $output" - echo "status: $status" - - assert_success - assert_output 'hi dokku' -} - @test "(core) port exposure (dockerfile raw port)" { source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" cat< $DOCKERFILE diff --git a/tests/unit/40_core_2.bats b/tests/unit/core_2.bats similarity index 97% rename from tests/unit/40_core_2.bats rename to tests/unit/core_2.bats index 21a7d3e65..9a0de63d1 100644 --- a/tests/unit/40_core_2.bats +++ b/tests/unit/core_2.bats @@ -22,7 +22,7 @@ teardown() { @test "(core) run (with --options)" { deploy_app - run /bin/bash -c "dokku --force --quiet run $TEST_APP node --version" + run /bin/bash -c "dokku --force --quiet run $TEST_APP python -V" echo "output: $output" echo "status: $status" assert_success diff --git a/tests/unit/core_3.bats b/tests/unit/core_3.bats new file mode 100644 index 000000000..66c271d3f --- /dev/null +++ b/tests/unit/core_3.bats @@ -0,0 +1,120 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app + DOCKERFILE="$BATS_TMPDIR/Dockerfile" +} + +teardown() { + rm -rf /home/dokku/$TEST_APP/tls + destroy_app + dokku config:unset --global DOKKU_RM_CONTAINER + rm -f "$DOCKERFILE" + global_teardown +} + +@test "(core) run (with DOKKU_RM_CONTAINER/--rm-container)" { + deploy_app + + run /bin/bash -c "dokku --rm-container run $TEST_APP echo $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "dokku config:set --no-restart $TEST_APP DOKKU_RM_CONTAINER=1" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku --rm-container run $TEST_APP echo $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "dokku config:unset --no-restart $TEST_APP DOKKU_RM_CONTAINER" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku config:set --global DOKKU_RM_CONTAINER=1" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku --rm-container run $TEST_APP echo $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "docker ps -a -f 'status=exited' --no-trunc=true | grep \"/exec echo $TEST_APP\"" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "dokku config:unset --global DOKKU_RM_CONTAINER" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(core) run (detached)" { + deploy_app + + RANDOM_RUN_CID="$(dokku --label=com.dokku.test-label=value --detach run $TEST_APP sleep 300)" + run /bin/bash -c "docker inspect -f '{{ .State.Status }}' $RANDOM_RUN_CID" + echo "output: $output" + echo "status: $status" + assert_output "running" + + run /bin/bash -c "docker inspect $RANDOM_RUN_CID --format '{{ index .Config.Labels \"com.dokku.test-label\" }}'" + echo "output: $output" + echo "status: $status" + assert_output "value" + + run /bin/bash -c "docker stop $RANDOM_RUN_CID" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku cleanup" + echo "output: $output" + echo "status: $status" + assert_success + sleep 5 # wait for dokku cleanup to happen in the background +} + +@test "(core) run (with tty)" { + deploy_app + run /bin/bash -c "dokku run $TEST_APP ls /app/null" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(core) run (without tty)" { + deploy_app + run /bin/bash -c ": |dokku run $TEST_APP ls /app/null" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(core) run command from Procfile" { + deploy_app + run /bin/bash -c "dokku run $TEST_APP custom 'hi dokku' | tail -n 1" + echo "output: $output" + echo "status: $status" + + assert_success + assert_output 'hi dokku' +} diff --git a/tests/unit/20_docker-options.bats b/tests/unit/docker-options.bats similarity index 100% rename from tests/unit/20_docker-options.bats rename to tests/unit/docker-options.bats diff --git a/tests/unit/20_domains.bats b/tests/unit/domains.bats similarity index 100% rename from tests/unit/20_domains.bats rename to tests/unit/domains.bats diff --git a/tests/unit/30_events.bats b/tests/unit/events.bats similarity index 100% rename from tests/unit/30_events.bats rename to tests/unit/events.bats diff --git a/tests/unit/git_1.bats b/tests/unit/git_1.bats new file mode 100644 index 000000000..63bf3714b --- /dev/null +++ b/tests/unit/git_1.bats @@ -0,0 +1,73 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + global_teardown +} + +@test "(git) git:help" { + run /bin/bash -c "dokku git" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage app deploys via git" + help_output="$output" + + run /bin/bash -c "dokku git:help" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage app deploys via git" + assert_output "$help_output" +} + +@test "(git) ensure GIT_REV env var is set" { + deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku config:get $TEST_APP GIT_REV" + echo "output: $output" + echo "status: $status" + assert_output_exists +} + +@test "(git) disable GIT_REV" { + run /bin/bash -c "dokku git:set $TEST_APP rev-env-var" + echo "output: $output" + echo "status: $status" + assert_success + + deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku config:get $TEST_APP GIT_REV" + echo "output: $output" + echo "status: $status" + assert_output "" +} + +@test "(git) customize the GIT_REV environment variable" { + run /bin/bash -c "dokku git:set $TEST_APP rev-env-var GIT_REV_ALT" + echo "output: $output" + echo "status: $status" + assert_success + + deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku config:get $TEST_APP GIT_REV_ALT" + echo "output: $output" + echo "status: $status" + assert_output_exists +} diff --git a/tests/unit/10_git.bats b/tests/unit/git_2.bats similarity index 55% rename from tests/unit/10_git.bats rename to tests/unit/git_2.bats index d258b4c01..d9ad4e084 100644 --- a/tests/unit/10_git.bats +++ b/tests/unit/git_2.bats @@ -12,20 +12,6 @@ teardown() { global_teardown } -@test "(git) git:help" { - run /bin/bash -c "dokku git" - echo "output: $output" - echo "status: $status" - assert_output_contains "Manage app deploys via git" - help_output="$output" - - run /bin/bash -c "dokku git:help" - echo "output: $output" - echo "status: $status" - assert_output_contains "Manage app deploys via git" - assert_output "$help_output" -} - @test "(git) deploy specific branch" { run /bin/bash -c "dokku git:set --global deploy-branch global-branch" echo "output: $output" @@ -62,52 +48,6 @@ teardown() { run /bin/bash -c "dokku git:set --global deploy-branch" } -@test "(git) ensure GIT_REV env var is set" { - deploy_app - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku config:get $TEST_APP GIT_REV" - echo "output: $output" - echo "status: $status" - assert_output_exists -} - -@test "(git) disable GIT_REV" { - run /bin/bash -c "dokku git:set $TEST_APP rev-env-var" - echo "output: $output" - echo "status: $status" - assert_success - - deploy_app - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku config:get $TEST_APP GIT_REV" - echo "output: $output" - echo "status: $status" - assert_output "" -} - -@test "(git) customize the GIT_REV environment variable" { - run /bin/bash -c "dokku git:set $TEST_APP rev-env-var GIT_REV_ALT" - echo "output: $output" - echo "status: $status" - assert_success - - deploy_app - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku config:get $TEST_APP GIT_REV_ALT" - echo "output: $output" - echo "status: $status" - assert_output_exists -} - @test "(git) git:initialize" { run /bin/bash -c "test -d $DOKKU_ROOT/$TEST_APP/refs" echo "output: $output" diff --git a/tests/unit/init.bats b/tests/unit/init.bats new file mode 100644 index 000000000..80b1bbf33 --- /dev/null +++ b/tests/unit/init.bats @@ -0,0 +1,46 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + global_teardown +} + +@test "(init) buildpack" { + source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + local APP="zombies-buildpack" + deploy_app "$APP" + local CIDS=$(get_app_container_ids "$APP") + + run "$DOCKER_BIN" container top "$CIDS" + echo "output: $output" + assert_output_contains "" "0" +} + +@test "(init) dockerfile no tini" { + source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + local APP="zombies-dockerfile-no-tini" + deploy_app "$APP" + local CIDS=$(get_app_container_ids "$APP") + + run "$DOCKER_BIN" container top "$CIDS" + echo "output: $output" + assert_output_contains "" "0" +} + +@test "(init) dockerfile with tini" { + source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" + local APP="zombies-dockerfile-tini" + deploy_app "$APP" + local CIDS=$(get_app_container_ids "$APP") + + run "$DOCKER_BIN" container top "$CIDS" + echo "output: $output" + assert_output_contains "" "0" +} diff --git a/tests/unit/20_network.bats b/tests/unit/network.bats similarity index 100% rename from tests/unit/20_network.bats rename to tests/unit/network.bats diff --git a/tests/unit/nginx-vhosts_1.bats b/tests/unit/nginx-vhosts_1.bats new file mode 100644 index 000000000..2995e478c --- /dev/null +++ b/tests/unit/nginx-vhosts_1.bats @@ -0,0 +1,71 @@ +#!/usr/bin/env bats + +load test_helper +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" + +setup() { + global_setup + [[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak" + [[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak" +} + +teardown() { + detach_delete_network + destroy_app + [[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST" + [[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME" + global_teardown +} + +@test "(nginx) nginx:help" { + run /bin/bash -c "dokku nginx" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage the nginx proxy" + help_output="$output" + + run /bin/bash -c "dokku nginx:help" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage the nginx proxy" + assert_output "$help_output" +} + +@test "(nginx-vhosts) nginx:build-config (domains:disable/enable)" { + deploy_app + dokku domains:disable $TEST_APP + + HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME") + check_urls http://${HOSTNAME}:[0-9]+ + + URLS=$(dokku --quiet urls "$TEST_APP") + for URL in $URLS; do + assert_http_success $URL + done + + dokku domains:enable $TEST_APP + check_urls http://${TEST_APP}.dokku.me + assert_http_success http://${TEST_APP}.dokku.me +} + +@test "(nginx-vhosts) nginx:build-config (domains:add pre deploy)" { + create_app + run /bin/bash -c "dokku domains:add $TEST_APP www.test.app.dokku.me" + echo "output: $output" + echo "status: $status" + assert_success + + deploy_app + sleep 5 # wait for nginx to reload + + check_urls http://www.test.app.dokku.me + assert_http_success http://www.test.app.dokku.me +} + +@test "(nginx-vhosts) nginx:build-config (with global VHOST)" { + echo "dokku.me" > "$DOKKU_ROOT/VHOST" + deploy_app + + check_urls http://${TEST_APP}.dokku.me + assert_http_success http://${TEST_APP}.dokku.me +} diff --git a/tests/unit/nginx-vhosts_2.bats b/tests/unit/nginx-vhosts_2.bats new file mode 100644 index 000000000..ed985806f --- /dev/null +++ b/tests/unit/nginx-vhosts_2.bats @@ -0,0 +1,58 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + [[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak" + [[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak" + create_app +} + +teardown() { + destroy_app 0 $TEST_APP + [[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST" + [[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME" + global_teardown +} + +@test "(nginx-vhosts) nginx:build-config (with SSL and unrelated domain)" { + setup_test_tls + add_domain "node-js-app.dokku.me" + add_domain "test.dokku.me" + deploy_app + dokku nginx:show-config $TEST_APP + assert_ssl_domain "node-js-app.dokku.me" + assert_http_redirect "http://test.dokku.me" "https://test.dokku.me:443/" +} + +@test "(nginx-vhosts) nginx:build-config (wildcard SSL)" { + setup_test_tls wildcard + add_domain "wildcard1.dokku.me" + add_domain "wildcard2.dokku.me" + deploy_app + dokku nginx:show-config $TEST_APP + assert_ssl_domain "wildcard1.dokku.me" + assert_ssl_domain "wildcard2.dokku.me" +} + +@test "(nginx-vhosts) nginx:build-config (wildcard SSL and unrelated domain)" { + destroy_app + TEST_APP="${TEST_APP}.example.com" + setup_test_tls wildcard + deploy_app nodejs-express dokku@dokku.me:$TEST_APP + run /bin/bash -c "dokku nginx:show-config $TEST_APP | grep -e '*.dokku.me' | wc -l" + dokku nginx:show-config $TEST_APP + assert_output "0" +} + +@test "(nginx-vhosts) nginx:build-config (with SSL and Multiple SANs)" { + setup_test_tls sans + add_domain "test.dokku.me" + add_domain "www.test.dokku.me" + add_domain "www.test.app.dokku.me" + deploy_app + assert_ssl_domain "test.dokku.me" + assert_ssl_domain "www.test.dokku.me" + assert_ssl_domain "www.test.app.dokku.me" +} diff --git a/tests/unit/40_nginx-vhosts_3.bats b/tests/unit/nginx-vhosts_3.bats similarity index 100% rename from tests/unit/40_nginx-vhosts_3.bats rename to tests/unit/nginx-vhosts_3.bats diff --git a/tests/unit/nginx-vhosts_4.bats b/tests/unit/nginx-vhosts_4.bats new file mode 100644 index 000000000..97f576b87 --- /dev/null +++ b/tests/unit/nginx-vhosts_4.bats @@ -0,0 +1,71 @@ +#!/usr/bin/env bats + +load test_helper +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" + +setup() { + global_setup + [[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak" + [[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak" +} + +teardown() { + detach_delete_network + destroy_app + [[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST" + [[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME" + global_teardown +} + +@test "(nginx-vhosts) nginx:build-config (without global VHOST but real HOSTNAME)" { + rm "$DOKKU_ROOT/VHOST" + echo "${TEST_APP}.dokku.me" > "$DOKKU_ROOT/HOSTNAME" + deploy_app + + HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME") + check_urls http://${HOSTNAME}:[0-9]+ + + URLS=$(dokku --quiet urls "$TEST_APP") + for URL in $URLS; do + assert_http_success $URL + done +} + +@test "(nginx-vhosts) nginx:build-config (without global VHOST and IPv4 address set as HOSTNAME)" { + rm "$DOKKU_ROOT/VHOST" + echo "127.0.0.1" > "$DOKKU_ROOT/HOSTNAME" + deploy_app + + HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME") + check_urls http://${HOSTNAME}:[0-9]+ + + URLS=$(dokku --quiet urls "$TEST_APP") + for URL in $URLS; do + assert_http_success $URL + done +} + +@test "(nginx-vhosts) nginx:build-config (without global VHOST and IPv6 address set as HOSTNAME)" { + rm "$DOKKU_ROOT/VHOST" + echo "fda5:c7db:a520:bb6d::aabb:ccdd:eeff" > "$DOKKU_ROOT/HOSTNAME" + deploy_app + + HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME") + check_urls http://${HOSTNAME}:[0-9]+ +} + +@test "(nginx-vhosts) nginx:build-config (without global VHOST and domains:add pre deploy)" { + rm "$DOKKU_ROOT/VHOST" + create_app + add_domain "www.test.app.dokku.me" + deploy_app + assert_nonssl_domain "www.test.app.dokku.me" +} + +@test "(nginx-vhosts) nginx:build-config (without global VHOST and domains:add post deploy)" { + rm "$DOKKU_ROOT/VHOST" + deploy_app + add_domain "www.test.app.dokku.me" + check_urls http://www.test.app.dokku.me + assert_http_success http://www.test.app.dokku.me +} diff --git a/tests/unit/nginx-vhosts_5.bats b/tests/unit/nginx-vhosts_5.bats new file mode 100644 index 000000000..70dbf1971 --- /dev/null +++ b/tests/unit/nginx-vhosts_5.bats @@ -0,0 +1,62 @@ +#!/usr/bin/env bats + +load test_helper +source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions" + +setup() { + global_setup + [[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak" + [[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak" +} + +teardown() { + detach_delete_network + destroy_app + [[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST" + [[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME" + global_teardown +} + +@test "(nginx-vhosts) nginx:build-config (xip.io style hostnames)" { + echo "127.0.0.1.xip.io.dokku.me" > "$DOKKU_ROOT/VHOST" + deploy_app + + check_urls http://${TEST_APP}.127.0.0.1.xip.io.dokku.me + assert_http_success http://${TEST_APP}.127.0.0.1.xip.io.dokku.me +} + +@test "(nginx-vhosts) nginx:build-config (dockerfile expose)" { + deploy_app dockerfile + + add_domain "www.test.app.dokku.me" + check_urls http://${TEST_APP}.dokku.me:3000 + check_urls http://${TEST_APP}.dokku.me:3003 + check_urls http://www.test.app.dokku.me:3000 + check_urls http://www.test.app.dokku.me:3003 + assert_http_success http://${TEST_APP}.dokku.me:3000 + assert_http_success http://${TEST_APP}.dokku.me:3003 + assert_http_success http://www.test.app.dokku.me:3000 + assert_http_success http://www.test.app.dokku.me:3003 + +} + +@test "(nginx-vhosts) nginx:build-config (multiple networks)" { + deploy_app + + create_attach_network + run /bin/bash -c "dokku nginx:build-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(nginx-vhosts) nginx:build-config (global DOKKU_PROXY_PORT)" { + local GLOBAL_PORT=30999 + run /bin/bash -c "dokku config:set --global DOKKU_PROXY_PORT=${GLOBAL_PORT}" + + deploy_app + check_urls http://${TEST_APP}.dokku.me:${GLOBAL_PORT} + assert_http_success http://${TEST_APP}.dokku.me:${GLOBAL_PORT} + + run /bin/bash -c "dokku config:unset --global DOKKU_PROXY_PORT" +} diff --git a/tests/unit/40_nginx-vhosts_2.bats b/tests/unit/nginx-vhosts_6.bats similarity index 53% rename from tests/unit/40_nginx-vhosts_2.bats rename to tests/unit/nginx-vhosts_6.bats index e5d944879..0ff29f4e5 100644 --- a/tests/unit/40_nginx-vhosts_2.bats +++ b/tests/unit/nginx-vhosts_6.bats @@ -24,175 +24,6 @@ teardown() { assert_failure } -@test "(nginx-vhosts) logging" { - deploy_app - - run [ -a "/var/log/nginx/$TEST_APP-access.log" ] - echo "output: $output" - echo "status: $status" - assert_success - - run [ -a "/var/log/nginx/$TEST_APP-error.log" ] - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:access-logs $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:error-logs $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success -} - -@test "(nginx-vhosts) log-path" { - deploy_app - - run /bin/bash -c "dokku nginx:set $TEST_APP access-log-path off" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:build-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:show-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_output_contains "off;" - - run /bin/bash -c "dokku nginx:set $TEST_APP access-log-path" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:build-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:show-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_output_contains "off;" 0 - - run /bin/bash -c "dokku nginx:set $TEST_APP error-log-path off" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:build-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:show-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_output_contains "off;" - - run /bin/bash -c "dokku nginx:set $TEST_APP error-log-path" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:build-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku nginx:show-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_output_contains "off;" 0 -} - -@test "(nginx-vhosts) nginx:build-config (with SSL and unrelated domain)" { - setup_test_tls - add_domain "node-js-app.dokku.me" - add_domain "test.dokku.me" - deploy_app - dokku nginx:show-config $TEST_APP - assert_ssl_domain "node-js-app.dokku.me" - assert_http_redirect "http://test.dokku.me" "https://test.dokku.me:443/" -} - -@test "(nginx-vhosts) nginx:build-config (wildcard SSL)" { - setup_test_tls wildcard - add_domain "wildcard1.dokku.me" - add_domain "wildcard2.dokku.me" - deploy_app - dokku nginx:show-config $TEST_APP - assert_ssl_domain "wildcard1.dokku.me" - assert_ssl_domain "wildcard2.dokku.me" -} - -@test "(nginx-vhosts) nginx:build-config (wildcard SSL and unrelated domain)" { - destroy_app - TEST_APP="${TEST_APP}.example.com" - setup_test_tls wildcard - deploy_app nodejs-express dokku@dokku.me:$TEST_APP - run /bin/bash -c "dokku nginx:show-config $TEST_APP | grep -e '*.dokku.me' | wc -l" - dokku nginx:show-config $TEST_APP - assert_output "0" -} - -@test "(nginx-vhosts) nginx:build-config (with SSL and Multiple SANs)" { - setup_test_tls sans - add_domain "test.dokku.me" - add_domain "www.test.dokku.me" - add_domain "www.test.app.dokku.me" - deploy_app - assert_ssl_domain "test.dokku.me" - assert_ssl_domain "www.test.dokku.me" - assert_ssl_domain "www.test.app.dokku.me" -} - -@test "(nginx-vhosts) nginx:build-config (wildcard SSL and custom nginx template)" { - setup_test_tls wildcard - add_domain "wildcard1.dokku.me" - add_domain "wildcard2.dokku.me" - deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_ssl_nginx_template - - assert_ssl_domain "wildcard1.dokku.me" - assert_ssl_domain "wildcard2.dokku.me" - assert_http_redirect "http://${CUSTOM_TEMPLATE_SSL_DOMAIN}" "https://${CUSTOM_TEMPLATE_SSL_DOMAIN}:443/" - assert_http_success "https://${CUSTOM_TEMPLATE_SSL_DOMAIN}" -} - -@test "(nginx-vhosts) nginx:build-config (custom nginx template - no ssl)" { - add_domain "www.test.app.dokku.me" - run deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_nginx_template - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku ps:scale $TEST_APP worker=1" - echo "output: $output" - echo "status: $status" - assert_success - - assert_nonssl_domain "www.test.app.dokku.me" - assert_http_success "customtemplate.dokku.me" - - run /bin/bash -c "dokku nginx:show-config $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_output_contains "${TEST_APP}-worker-5000" -} - -@test "(nginx-vhosts) nginx:build-config (failed validate_nginx)" { - run deploy_app nodejs-express dokku@dokku.me:$TEST_APP bad_custom_nginx_template - echo "output: $output" - echo "status: $status" - assert_failure -} - @test "(nginx-vhosts) nginx:set hsts" { setup_test_tls wildcard local HSTS_CONF="/home/dokku/${TEST_APP}/nginx.conf.d/hsts.conf" diff --git a/tests/unit/nginx-vhosts_7.bats b/tests/unit/nginx-vhosts_7.bats new file mode 100644 index 000000000..060676d28 --- /dev/null +++ b/tests/unit/nginx-vhosts_7.bats @@ -0,0 +1,57 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + [[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak" + [[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak" + create_app +} + +teardown() { + destroy_app 0 $TEST_APP + [[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST" + [[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME" + global_teardown +} + +@test "(nginx-vhosts) nginx:build-config (wildcard SSL and custom nginx template)" { + setup_test_tls wildcard + add_domain "wildcard1.dokku.me" + add_domain "wildcard2.dokku.me" + deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_ssl_nginx_template + + assert_ssl_domain "wildcard1.dokku.me" + assert_ssl_domain "wildcard2.dokku.me" + assert_http_redirect "http://${CUSTOM_TEMPLATE_SSL_DOMAIN}" "https://${CUSTOM_TEMPLATE_SSL_DOMAIN}:443/" + assert_http_success "https://${CUSTOM_TEMPLATE_SSL_DOMAIN}" +} + +@test "(nginx-vhosts) nginx:build-config (custom nginx template - no ssl)" { + add_domain "www.test.app.dokku.me" + run deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_nginx_template + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:scale $TEST_APP worker=1" + echo "output: $output" + echo "status: $status" + assert_success + + assert_nonssl_domain "www.test.app.dokku.me" + assert_http_success "customtemplate.dokku.me" + + run /bin/bash -c "dokku nginx:show-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "${TEST_APP}-worker-5000" +} + +@test "(nginx-vhosts) nginx:build-config (failed validate_nginx)" { + run deploy_app nodejs-express dokku@dokku.me:$TEST_APP bad_custom_nginx_template + echo "output: $output" + echo "status: $status" + assert_failure +} diff --git a/tests/unit/nginx-vhosts_8.bats b/tests/unit/nginx-vhosts_8.bats new file mode 100644 index 000000000..c90095a02 --- /dev/null +++ b/tests/unit/nginx-vhosts_8.bats @@ -0,0 +1,125 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + [[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak" + [[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak" + create_app +} + +teardown() { + destroy_app 0 $TEST_APP + [[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST" + [[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME" + global_teardown +} + +@test "(nginx-vhosts) logging" { + deploy_app + + run [ -a "/var/log/nginx/$TEST_APP-access.log" ] + echo "output: $output" + echo "status: $status" + assert_success + + run [ -a "/var/log/nginx/$TEST_APP-error.log" ] + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:access-logs $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:error-logs $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success +} + +@test "(nginx-vhosts) log-path" { + deploy_app + + run /bin/bash -c "dokku nginx:set $TEST_APP access-log-path off" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:build-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:show-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "off;" + + run /bin/bash -c "dokku nginx:set $TEST_APP access-log-path" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:build-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:show-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "off;" 0 + + run /bin/bash -c "dokku nginx:set $TEST_APP error-log-path off" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:build-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:show-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "off;" + + run /bin/bash -c "dokku nginx:set $TEST_APP error-log-path" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:build-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku nginx:show-config $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "off;" 0 +} + +@test "(nginx-vhosts) nginx:build-config (with SSL and unrelated domain)" { + setup_test_tls + add_domain "node-js-app.dokku.me" + add_domain "test.dokku.me" + deploy_app + dokku nginx:show-config $TEST_APP + assert_ssl_domain "node-js-app.dokku.me" + assert_http_redirect "http://test.dokku.me" "https://test.dokku.me:443/" +} + +@test "(nginx-vhosts) nginx:build-config (wildcard SSL)" { + setup_test_tls wildcard + add_domain "wildcard1.dokku.me" + add_domain "wildcard2.dokku.me" + deploy_app + dokku nginx:show-config $TEST_APP + assert_ssl_domain "wildcard1.dokku.me" + assert_ssl_domain "wildcard2.dokku.me" +} diff --git a/tests/unit/40_plugin.bats b/tests/unit/plugin.bats similarity index 100% rename from tests/unit/40_plugin.bats rename to tests/unit/plugin.bats diff --git a/tests/unit/40_proxy.bats b/tests/unit/proxy.bats similarity index 100% rename from tests/unit/40_proxy.bats rename to tests/unit/proxy.bats diff --git a/tests/unit/ps-dockerfile-1.bats b/tests/unit/ps-dockerfile-1.bats new file mode 100644 index 000000000..bba89ed30 --- /dev/null +++ b/tests/unit/ps-dockerfile-1.bats @@ -0,0 +1,124 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + global_teardown +} + +@test "(ps) dockerfile" { + deploy_app dockerfile + run /bin/bash -c "dokku ps:stop $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do + run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" + echo "output: $output" + echo "status: $status" + assert_failure + done + + run /bin/bash -c "dokku ps:start $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do + run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" + echo "output: $output" + echo "status: $status" + assert_success + done + + run /bin/bash -c "dokku ps:restart $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do + run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" + echo "output: $output" + echo "status: $status" + assert_success + done + + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do + run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" + echo "output: $output" + echo "status: $status" + assert_success + done +} + +@test "(ps:scale) dockerfile non-existent process" { + run /bin/bash -c "dokku ps:scale $TEST_APP non-existent=2" + echo "output: $output" + echo "status: $status" + assert_success + + destroy_app + create_app + deploy_app dockerfile-procfile + run /bin/bash -c "dokku ps:scale $TEST_APP non-existent=2" + echo "output: $output" + echo "status: $status" + assert_failure +} + +@test "(ps:scale) dockerfile" { + run /bin/bash -c "dokku ps:scale $TEST_APP web=2" + echo "output: $output" + echo "status: $status" + assert_success + + deploy_app dockerfile + CIDS="" + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do + CIDS+=$(< $CID_FILE) + CIDS+=" " + done + CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 2" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:scale $TEST_APP web=1" + echo "output: $output" + echo "status: $status" + assert_success + CIDS="" + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do + CIDS+=$(< $CID_FILE) + CIDS+=" " + done + CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 1" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:scale $TEST_APP web=0" + echo "output: $output" + echo "status: $status" + assert_success + CIDS="" + shopt -s nullglob + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do + CIDS+=$(< $CID_FILE) + CIDS+=" " + done + run /bin/bash -c "[[ -z \"$CIDS\" ]]" + echo "output: $output" + echo "status: $status" + assert_success +} diff --git a/tests/unit/10_ps-herokuish.bats b/tests/unit/ps-dockerfile-2.bats similarity index 63% rename from tests/unit/10_ps-herokuish.bats rename to tests/unit/ps-dockerfile-2.bats index 1d77ce4ce..759f9013e 100644 --- a/tests/unit/10_ps-herokuish.bats +++ b/tests/unit/ps-dockerfile-2.bats @@ -9,12 +9,40 @@ setup() { teardown() { destroy_app - destroy_app 0 "$MYAPP" || true global_teardown } -@test "(ps) herokuish" { - deploy_app +@test "(ps:scale) dockerfile dokku-scale" { + run /bin/bash -c "dokku ps:scale $TEST_APP web=2" + echo "output: $output" + echo "status: $status" + assert_success + + deploy_app dockerfile-dokku-scale + CIDS="" + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do + CIDS+=$(< $CID_FILE) + CIDS+=" " + done + CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 1" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:scale $TEST_APP web=1" + echo "output: $output" + echo "status: $status" + assert_failure + + run /bin/bash -c "dokku ps:report $TEST_APP --ps-can-scale" + echo "output: $output" + echo "status: $status" + assert_output "false" +} + +@test "(ps) dockerfile with procfile" { + deploy_app dockerfile-procfile run /bin/bash -c "dokku ps:stop $TEST_APP" echo "output: $output" echo "status: $status" @@ -60,24 +88,36 @@ teardown() { done } -@test "(ps:scale) herokuish" { +@test "(ps) dockerfile with bad procfile" { + run deploy_app dockerfile-procfile-bad + echo "output: $output" + echo "status: $status" + assert_failure + + run create_app + assert_success +} + +@test "(ps:scale) dockerfile with procfile" { run /bin/bash -c "dokku ps:scale $TEST_APP web=2 worker=2" echo "output: $output" echo "status: $status" assert_success - deploy_app + deploy_app dockerfile-procfile for PROC_TYPE in web worker; do - CIDS="" - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do - CIDS+=$(< $CID_FILE) - CIDS+=" " - done - CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 2" + run /bin/bash -c "docker ps --format '{{.ID}} {{.Command}}' --no-trunc" echo "output: $output" echo "status: $status" assert_success + goodlines="" + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do + cid=$(< $CID_FILE) + assert_output_contains "$cid" + goodlines+=$(echo "$output" | grep "$cid") + done + output="$goodlines" + assert_output_contains "node ${PROC_TYPE}.js" 2 done run /bin/bash -c "dokku ps:scale $TEST_APP web=1 worker=1" @@ -85,23 +125,25 @@ teardown() { echo "status: $status" assert_success for PROC_TYPE in web worker; do - CIDS="" - for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do - CIDS+=$(< $CID_FILE) - CIDS+=" " - done - CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") - run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 1" + run /bin/bash -c "docker ps --format '{{.ID}} {{.Command}}' --no-trunc" echo "output: $output" echo "status: $status" assert_success + goodlines="" + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do + cid=$(< $CID_FILE) + assert_output_contains "$cid" + goodlines+=$(echo "$output" | grep "$cid") + done + output="$goodlines" + assert_output_contains "node ${PROC_TYPE}.js" done - run /bin/bash -c "dokku ps:scale $TEST_APP web=0 worker=0 invalid-process=0" + run /bin/bash -c "dokku ps:scale $TEST_APP web=0 worker=0" echo "output: $output" echo "status: $status" assert_success - for PROC_TYPE in web worker invalid-process; do + for PROC_TYPE in web worker; do CIDS="" shopt -s nullglob for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do @@ -115,29 +157,3 @@ teardown() { assert_success done } - -@test "(ps:restore) herokuish" { - MYAPP="manual-randomtestapp-1" - create_app "$MYAPP" - deploy_app - - run /bin/bash -c "dokku ps:stop $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku apps:list" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku ps:restore" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku --quiet ps:report $TEST_APP | grep -q exited" - echo "output: $output" - echo "status: $status" - assert_success -} diff --git a/tests/unit/10_ps-general.bats b/tests/unit/ps-general.bats similarity index 100% rename from tests/unit/10_ps-general.bats rename to tests/unit/ps-general.bats diff --git a/tests/unit/ps-herokuish-1.bats b/tests/unit/ps-herokuish-1.bats new file mode 100644 index 000000000..c6002ef66 --- /dev/null +++ b/tests/unit/ps-herokuish-1.bats @@ -0,0 +1,61 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + destroy_app 0 "$MYAPP" || true + global_teardown +} + +@test "(ps) herokuish" { + deploy_app + run /bin/bash -c "dokku ps:stop $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do + run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" + echo "output: $output" + echo "status: $status" + assert_failure + done + + run /bin/bash -c "dokku ps:start $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do + run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" + echo "output: $output" + echo "status: $status" + assert_success + done + + run /bin/bash -c "dokku ps:restart $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do + run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" + echo "output: $output" + echo "status: $status" + assert_success + done + + run /bin/bash -c "dokku ps:rebuild $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.*; do + run /bin/bash -c "docker ps -q --no-trunc | grep -q $(< $CID_FILE)" + echo "output: $output" + echo "status: $status" + assert_success + done +} diff --git a/tests/unit/ps-herokuish-2.bats b/tests/unit/ps-herokuish-2.bats new file mode 100644 index 000000000..0dc232717 --- /dev/null +++ b/tests/unit/ps-herokuish-2.bats @@ -0,0 +1,96 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + destroy_app 0 "$MYAPP" || true + global_teardown +} + +@test "(ps:scale) herokuish" { + run /bin/bash -c "dokku ps:scale $TEST_APP web=2 worker=2" + echo "output: $output" + echo "status: $status" + assert_success + + deploy_app + for PROC_TYPE in web worker; do + CIDS="" + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do + CIDS+=$(< $CID_FILE) + CIDS+=" " + done + CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 2" + echo "output: $output" + echo "status: $status" + assert_success + done + + run /bin/bash -c "dokku ps:scale $TEST_APP web=1 worker=1" + echo "output: $output" + echo "status: $status" + assert_success + for PROC_TYPE in web worker; do + CIDS="" + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do + CIDS+=$(< $CID_FILE) + CIDS+=" " + done + CIDS_PATTERN=$(echo $CIDS | sed -e "s: :|:g") + run /bin/bash -c "docker ps -q --no-trunc | grep -E \"$CIDS_PATTERN\" | wc -l | grep 1" + echo "output: $output" + echo "status: $status" + assert_success + done + + run /bin/bash -c "dokku ps:scale $TEST_APP web=0 worker=0 invalid-process=0" + echo "output: $output" + echo "status: $status" + assert_success + for PROC_TYPE in web worker invalid-process; do + CIDS="" + shopt -s nullglob + for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.$PROC_TYPE.*; do + CIDS+=$(< $CID_FILE) + CIDS+=" " + done + shopt -u nullglob + run /bin/bash -c "[[ -z \"$CIDS\" ]]" + echo "output: $output" + echo "status: $status" + assert_success + done +} + +@test "(ps:restore) herokuish" { + MYAPP="manual-randomtestapp-1" + create_app "$MYAPP" + deploy_app + + run /bin/bash -c "dokku ps:stop $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku apps:list" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku ps:restore" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku --quiet ps:report $TEST_APP | grep -q exited" + echo "output: $output" + echo "status: $status" + assert_success +} diff --git a/tests/unit/10_repo.bats b/tests/unit/repo.bats similarity index 77% rename from tests/unit/10_repo.bats rename to tests/unit/repo.bats index 9df856052..960836908 100644 --- a/tests/unit/10_repo.bats +++ b/tests/unit/repo.bats @@ -4,11 +4,9 @@ load test_helper setup() { global_setup - deploy_app } teardown() { - destroy_app global_teardown } @@ -27,11 +25,21 @@ teardown() { } @test "(repo) repo:gc, repo:purge-cache" { + run deploy_app + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "dokku repo:gc $TEST_APP" echo "output: $output" echo "status: $status" assert_success + run /bin/bash -c "touch $DOKKU_ROOT/$TEST_APP/cache/derp" + echo "output: $output" + echo "status: $status" + assert_success + run /bin/bash -c "find $DOKKU_ROOT/$TEST_APP/cache -type f | wc -l | grep 0" echo "output: $output" echo "status: $status" @@ -44,4 +52,9 @@ teardown() { echo "output: $output" echo "status: $status" assert_success + + run destroy_app + echo "output: $output" + echo "status: $status" + assert_success } diff --git a/tests/unit/40_report.bats b/tests/unit/report.bats similarity index 100% rename from tests/unit/40_report.bats rename to tests/unit/report.bats diff --git a/tests/unit/20_resource.bats b/tests/unit/resource_1.bats similarity index 52% rename from tests/unit/20_resource.bats rename to tests/unit/resource_1.bats index 5a3e61571..0a828e729 100644 --- a/tests/unit/20_resource.bats +++ b/tests/unit/resource_1.bats @@ -100,85 +100,6 @@ teardown() { assert_output "0" } -@test "(resource) resource:reserve" { - run /bin/bash -c "dokku resource:reserve $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_output_contains "resource reservation $TEST_APP information" - - deploy_app - run /bin/bash -c "dokku resource:reserve --memory 512MB $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) - run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" - echo "output: $output" - echo "status: $status" - assert_output "0" - - dokku ps:rebuild "$TEST_APP" - CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) - run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" - echo "output: $output" - echo "status: $status" - assert_output "536870912" - - run /bin/bash -c "dokku resource:reserve --memory 1024MB --process-type worker $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku resource:reserve --cpu 0.5 --process-type worker $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - dokku ps:rebuild "$TEST_APP" - CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) - run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" - echo "output: $output" - echo "status: $status" - assert_output "536870912" - - run /bin/bash -c "dokku resource:reserve-clear --process-type worker $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - dokku ps:rebuild "$TEST_APP" - CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) - run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" - echo "output: $output" - echo "status: $status" - assert_output "536870912" - - run /bin/bash -c "dokku resource:reserve-clear --process-type web $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - dokku ps:rebuild "$TEST_APP" - CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) - run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" - echo "output: $output" - echo "status: $status" - assert_output "536870912" - - run /bin/bash -c "dokku resource:reserve-clear $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - dokku ps:rebuild "$TEST_APP" - CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) - run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" - echo "output: $output" - echo "status: $status" - assert_output "0" -} - @test "(resource) resource:limit-clear" { run /bin/bash -c "dokku resource:limit-clear $TEST_APP" echo "output: $output" @@ -190,15 +111,3 @@ teardown() { echo "status: $status" assert_success } - -@test "(resource) resource:reserve-clear" { - run /bin/bash -c "dokku resource:reserve-clear $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success - - run /bin/bash -c "dokku resource:reserve-clear --process-type web $TEST_APP" - echo "output: $output" - echo "status: $status" - assert_success -} diff --git a/tests/unit/resource_2.bats b/tests/unit/resource_2.bats new file mode 100644 index 000000000..ab5ce4141 --- /dev/null +++ b/tests/unit/resource_2.bats @@ -0,0 +1,104 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + create_app +} + +teardown() { + destroy_app + global_teardown +} + +@test "(resource) resource:reserve" { + run /bin/bash -c "dokku resource:reserve $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_output_contains "resource reservation $TEST_APP information" + + deploy_app + run /bin/bash -c "dokku resource:reserve --memory 512MB $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) + run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" + echo "output: $output" + echo "status: $status" + assert_output "0" + + dokku ps:rebuild "$TEST_APP" + CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) + run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" + echo "output: $output" + echo "status: $status" + assert_output "536870912" + + run /bin/bash -c "dokku resource:reserve --memory 1024MB --process-type worker $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku resource:reserve --cpu 0.5 --process-type worker $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + dokku ps:rebuild "$TEST_APP" + CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) + run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" + echo "output: $output" + echo "status: $status" + assert_output "536870912" + + run /bin/bash -c "dokku resource:reserve-clear --process-type worker $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + dokku ps:rebuild "$TEST_APP" + CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) + run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" + echo "output: $output" + echo "status: $status" + assert_output "536870912" + + run /bin/bash -c "dokku resource:reserve-clear --process-type web $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + dokku ps:rebuild "$TEST_APP" + CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) + run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" + echo "output: $output" + echo "status: $status" + assert_output "536870912" + + run /bin/bash -c "dokku resource:reserve-clear $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + dokku ps:rebuild "$TEST_APP" + CID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1) + run /bin/bash -c "docker inspect --format '{{.HostConfig.MemoryReservation}}' $CID" + echo "output: $output" + echo "status: $status" + assert_output "0" +} + +@test "(resource) resource:reserve-clear" { + run /bin/bash -c "dokku resource:reserve-clear $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku resource:reserve-clear --process-type web $TEST_APP" + echo "output: $output" + echo "status: $status" + assert_success +} diff --git a/tests/unit/30_scheduler-docker-local.bats b/tests/unit/scheduler-docker-local.bats similarity index 100% rename from tests/unit/30_scheduler-docker-local.bats rename to tests/unit/scheduler-docker-local.bats diff --git a/tests/unit/30_ssh_keys.bats b/tests/unit/ssh_keys.bats similarity index 100% rename from tests/unit/30_ssh_keys.bats rename to tests/unit/ssh_keys.bats diff --git a/tests/unit/20_storage.bats b/tests/unit/storage.bats similarity index 100% rename from tests/unit/20_storage.bats rename to tests/unit/storage.bats diff --git a/tests/unit/40_tags.bats b/tests/unit/tags.bats similarity index 100% rename from tests/unit/40_tags.bats rename to tests/unit/tags.bats diff --git a/tests/unit/10_tar.bats b/tests/unit/tar.bats similarity index 100% rename from tests/unit/10_tar.bats rename to tests/unit/tar.bats diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index 5ca474caa..99cef20d5 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -20,8 +20,8 @@ SKIPPED_TEST_ERR_MSG="previous test failed! skipping remaining tests..." global_setup() { [[ ! -f "${BATS_PARENT_TMPNAME}.skip" ]] || skip "$SKIPPED_TEST_ERR_MSG" - dokku apps:list - docker container ls + dokku --quiet apps:list + docker container ls --quiet free -m docker container ls --quiet | xargs -n1 docker container rm -f || true } @@ -263,7 +263,7 @@ assert_urls() { deploy_app() { declare APP_TYPE="$1" GIT_REMOTE="$2" CUSTOM_TEMPLATE="$3" CUSTOM_PATH="$4" - local APP_TYPE=${APP_TYPE:="nodejs-express"} + local APP_TYPE=${APP_TYPE:="python"} local GIT_REMOTE=${GIT_REMOTE:="dokku@dokku.me:$TEST_APP"} local GIT_REMOTE_BRANCH=${GIT_REMOTE_BRANCH:="master"} local TMP=${CUSTOM_TMP:=$(mktemp -d "/tmp/dokku.me.XXXXX")} diff --git a/tests/unit/40_trace.bats b/tests/unit/trace.bats similarity index 100% rename from tests/unit/40_trace.bats rename to tests/unit/trace.bats diff --git a/tests/unit/10_version.bats b/tests/unit/version.bats similarity index 100% rename from tests/unit/10_version.bats rename to tests/unit/version.bats