From 0948e2813a91bd2f05ffc4641ad1926fab6ed6b1 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Tue, 19 Mar 2019 14:59:49 -0400 Subject: [PATCH] chore: unify with other plugins --- .gitignore | 1 - .travis.yml | 1 + Makefile | 30 +++++++++++++++++++++++------- Vagrantfile | 9 +++------ common-functions | 2 +- subcommands/clone | 2 +- subcommands/create | 2 +- subcommands/expose | 2 +- subcommands/link | 2 +- subcommands/upgrade | 2 +- tests/service_logs.bats | 20 ++++++++++++++++---- 11 files changed, 49 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index aa908dc..8235dba 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ /tmp -/test-results .vagrant diff --git a/.travis.yml b/.travis.yml index 8eb8e5b..e263f95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,4 @@ env: - DOKKU_VERSION=v0.12.0 install: make setup script: make test +after_failure: make report diff --git a/Makefile b/Makefile index fecaba6..c11a041 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ -SYSTEM := $(shell sh -c 'uname -s 2>/dev/null') +HARDWARE = $(shell uname -m) +SYSTEM_NAME = $(shell uname -s | tr '[:upper:]' '[:lower:]') bats: -ifeq ($(SYSTEM),Darwin) +ifeq ($(SYSTEM_NAME),darwin) ifneq ($(shell bats --version >/dev/null 2>&1 ; echo $$?),0) brew install bats-core endif @@ -13,7 +14,7 @@ endif shellcheck: ifneq ($(shell shellcheck --version >/dev/null 2>&1 ; echo $$?),0) -ifeq ($(SYSTEM),Darwin) +ifeq ($(SYSTEM_NAME),darwin) brew install shellcheck else sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse' @@ -44,7 +45,7 @@ endif ci-dependencies: shellcheck bats readlink lint-setup: - @mkdir -p test-results/shellcheck tmp/shellcheck + @mkdir -p tmp/test-results/shellcheck tmp/shellcheck @find . -not -path '*/\.*' -type f | xargs file | grep text | awk -F ':' '{ print $$1 }' | xargs head -n1 | egrep -B1 "bash" | grep "==>" | awk '{ print $$2 }' > tmp/shellcheck/test-files @cat tests/shellcheck-exclude | sed -n -e '/^# SC/p' | cut -d' ' -f2 | paste -d, -s - > tmp/shellcheck/exclude @@ -52,16 +53,31 @@ lint: lint-setup # these are disabled due to their expansive existence in the codebase. we should clean it up though @cat tests/shellcheck-exclude | sed -n -e '/^# SC/p' @echo linting... - @cat tmp/shellcheck/test-files | xargs shellcheck -e $(shell cat tmp/shellcheck/exclude) | tests/shellcheck-to-junit --output test-results/shellcheck/results.xml --files tmp/shellcheck/test-files --exclude $(shell cat tmp/shellcheck/exclude) + @cat tmp/shellcheck/test-files | xargs shellcheck -e $(shell cat tmp/shellcheck/exclude) | tests/shellcheck-to-junit --output tmp/test-results/shellcheck/results.xml --files tmp/shellcheck/test-files --exclude $(shell cat tmp/shellcheck/exclude) unit-tests: @echo running unit tests... - @mkdir -p test-results/bats + @mkdir -p tmp/test-results/bats @cd tests && echo "executing tests: $(shell cd tests ; ls *.bats | xargs)" - cd tests && bats --formatter bats-format-junit -e -T -o ../test-results/bats *.bats + cd tests && bats --formatter bats-format-junit -e -T -o ../tmp/test-results/bats *.bats + +tmp/xunit-to-github: + mkdir -p tmp + curl -o tmp/xunit-to-github.tgz -sL https://github.com/josegonzalez/go-xunit-to-github/releases/download/v0.3.0/xunit-to-github_0.3.0_$(SYSTEM_NAME)_$(HARDWARE).tgz + tar xf tmp/xunit-to-github.tgz -C tmp + chmod +x tmp/xunit-to-github setup: bash tests/setup.sh $(MAKE) ci-dependencies test: lint unit-tests + +report: tmp/xunit-to-github +ifdef TRAVIS_REPO_SLUG +ifdef GITHUB_ACCESS_TOKEN +ifneq ($(TRAVIS_PULL_REQUEST),false) + tmp/xunit-to-github --skip-ok --job-url "$(TRAVIS_JOB_WEB_URL)" --pull-request-id "$(TRAVIS_PULL_REQUEST)" --repository-slug "$(TRAVIS_REPO_SLUG)" --title "DOKKU_VERSION=$(DOKKU_VERSION)" tmp/test-results/bats tmp/test-results/shellcheck +endif +endif +endif diff --git a/Vagrantfile b/Vagrantfile index 21efd2a..e17cf9a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -1,8 +1,8 @@ # -*- mode: ruby -*- # vi: set ft=ruby : -BOX_NAME = ENV["BOX_NAME"] || "bento/ubuntu-14.04" -BOX_MEMORY = ENV["BOX_MEMORY"] || "512" +BOX_NAME = ENV["BOX_NAME"] || "bento/ubuntu-18.04" +BOX_MEMORY = ENV["BOX_MEMORY"] || "2048" DOKKU_VERSION = "master" Vagrant.configure(2) do |config| @@ -10,9 +10,6 @@ Vagrant.configure(2) do |config| config.ssh.forward_agent = true config.vm.provider :virtualbox do |vb| - # Ubuntu's Raring 64-bit cloud image is set to a 32-bit Ubuntu OS type by - # default in Virtualbox and thus will not boot. Manually override that. - vb.customize ["modifyvm", :id, "--ostype", "Ubuntu_64"] vb.customize ["modifyvm", :id, "--memory", BOX_MEMORY] end @@ -23,7 +20,7 @@ Vagrant.configure(2) do |config| config.vm.define "default", primary: true do |vm| vm.vm.synced_folder File.dirname(__FILE__), "/vagrant" - vm.vm.provision :shell, :inline => "apt-get update > /dev/null && apt-get install -y -qq git software-properties-common" + vm.vm.provision :shell, :inline => "apt -q update && apt -y -qq install git software-properties-common" vm.vm.provision :shell, :inline => "cd /vagrant && DOKKU_VERSION=#{DOKKU_VERSION} make setup" vm.vm.provision :shell, :inline => "cd /vagrant && DOKKU_TRACE=1 DOKKU_VERSION=#{DOKKU_VERSION} make test" end diff --git a/common-functions b/common-functions index 1f9ec25..5c36ceb 100755 --- a/common-functions +++ b/common-functions @@ -474,7 +474,7 @@ service_logs() { is_container_status "$ID" "Running" || dokku_log_warn "Service logs may not be output as service is not running" # shellcheck disable=SC2086 - docker logs $DOKKU_LOGS_ARGS "$ID" 2> /dev/null + docker logs $DOKKU_LOGS_ARGS "$ID" 2>&1 } service_parse_args() { diff --git a/subcommands/clone b/subcommands/clone index bc8fe48..df7648f 100755 --- a/subcommands/clone +++ b/subcommands/clone @@ -16,7 +16,7 @@ service-clone-cmd() { #F -r|--root-password PASSWORD, override the root-level service password declare desc="create container then copy data from into " local cmd="$PLUGIN_COMMAND_PREFIX:clone" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 - declare SERVICE="$1" NEW_SERVICE="$2" CLONE_FLAGS_LIST="${@:3}" + declare SERVICE="$1" NEW_SERVICE="$2" CLONE_FLAGS_LIST=("${@:3}") is_implemented_command "$cmd" || dokku_log_fail "Not yet implemented" [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" diff --git a/subcommands/create b/subcommands/create index e5135b3..abc5d9e 100755 --- a/subcommands/create +++ b/subcommands/create @@ -24,7 +24,7 @@ service-create-cmd() { #F -r|--root-password PASSWORD, override the root-level service password declare desc="create a $PLUGIN_SERVICE service" local cmd="$PLUGIN_COMMAND_PREFIX:create" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 - declare SERVICE="$1" CREATE_FLAGS_LIST="${@:2}" + declare SERVICE="$1" CREATE_FLAGS_LIST=("${@:2}") service_create "$SERVICE" "${@:2}" } diff --git a/subcommands/expose b/subcommands/expose index bcee26c..684359e 100755 --- a/subcommands/expose +++ b/subcommands/expose @@ -11,7 +11,7 @@ service-expose-cmd() { #A ports, a list of ports to run against declare desc="expose a $PLUGIN_SERVICE service on custom port if provided (random port otherwise)" local cmd="$PLUGIN_COMMAND_PREFIX:expose" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 - declare SERVICE="$1" PORTS_LIST="${@:2}" + declare SERVICE="$1" PORTS_LIST=("${@:2}") [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" verify_service_name "$SERVICE" diff --git a/subcommands/link b/subcommands/link index f3f276d..24d7ba3 100755 --- a/subcommands/link +++ b/subcommands/link @@ -43,7 +43,7 @@ service-link-cmd() { #F -q|--querystring "pool=5", ampersand delimited querystring arguments to append to the service link declare desc="link the $PLUGIN_SERVICE service to the app" local cmd="$PLUGIN_COMMAND_PREFIX:link" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 - declare SERVICE="$1" APP="$2" LINK_FLAGS_LIST="${@:3}" + declare SERVICE="$1" APP="$2" LINK_FLAGS_LIST=("${@:3}") APP=${APP:="$DOKKU_APP_NAME"} [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" diff --git a/subcommands/upgrade b/subcommands/upgrade index 800b15e..1234003 100755 --- a/subcommands/upgrade +++ b/subcommands/upgrade @@ -15,7 +15,7 @@ service-upgrade-cmd() { #F -R|--restart-apps "true", whether to force an app restart declare desc="upgrade service to the specified versions" local cmd="$PLUGIN_COMMAND_PREFIX:upgrade" argv=("$@"); [[ ${argv[0]} == "$cmd" ]] && shift 1 - declare SERVICE="$1" UPGRADE_FLAGS_LIST="${@:2}" + declare SERVICE="$1" UPGRADE_FLAGS_LIST=("${@:2}") [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" verify_service_name "$SERVICE" diff --git a/tests/service_logs.bats b/tests/service_logs.bats index 57905ce..d12585c 100755 --- a/tests/service_logs.bats +++ b/tests/service_logs.bats @@ -11,20 +11,32 @@ teardown() { @test "($PLUGIN_COMMAND_PREFIX:logs) error when there are no arguments" { run dokku "$PLUGIN_COMMAND_PREFIX:logs" + echo "output: $output" + echo "status: $status" assert_contains "${lines[*]}" "Please specify a valid name for the service" + assert_failure } @test "($PLUGIN_COMMAND_PREFIX:logs) error when service does not exist" { run dokku "$PLUGIN_COMMAND_PREFIX:logs" not_existing_service + echo "output: $output" + echo "status: $status" assert_contains "${lines[*]}" "service not_existing_service does not exist" + assert_failure } @test "($PLUGIN_COMMAND_PREFIX:logs) success when not tailing" { + skip "This may fail if there is no log output" run dokku "$PLUGIN_COMMAND_PREFIX:logs" l + echo "output: $output" + echo "status: $status" assert_success } -# @test "($PLUGIN_COMMAND_PREFIX:logs) success when tailing" { -# run dokku "$PLUGIN_COMMAND_PREFIX:logs" l -t -# assert_contains "docker logs --follow testid" -# } +@test "($PLUGIN_COMMAND_PREFIX:logs) success when tailing" { + skip "This will hang as it waits for log output" + run dokku "$PLUGIN_COMMAND_PREFIX:logs" l -t + echo "output: $output" + echo "status: $status" + assert_success +}