tests: run mvdan/shfmt on test runs

While I do not agree with _every_ style change, this will force Dokku to have consistent formatting across all shell scripts, which is arguably a Good Thing™.

The command used to reprocess everything is:

```shell
shfmt -l -bn -ci -i 2 -w .
```
This commit is contained in:
Jose Diaz-Gonzalez
2019-01-07 01:04:17 -05:00
parent fb7c73a7e3
commit 86795ddacc
283 changed files with 1536 additions and 1018 deletions

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S -i -N -H \"Connection: Upgrade\" -H \"Upgrade: websocket\" -H \"Host: $1\" -H \"Origin: $1\" $1 -m 2)"; echo $output; test "$output" == "bazingaa"
set -e
output="$(curl -s -S -i -N -H \"Connection: Upgrade\" -H \"Upgrade: websocket\" -H \"Host: $1\" -H \"Origin: $1\" $1 -m 2)"
echo $output
test "$output" == "bazingaa"

View File

@@ -1,2 +1,6 @@
#!/usr/bin/env bash
set -e; sleep 5; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello World!"
set -e
sleep 5
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "Hello World!"

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e;
set -e
test_url () {
test_url() {
path="$1"
expected_output="$2"
url="$base_url$path"

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -ex;
set -ex
REMOTE=$1
REPO=$2

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello World!"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "Hello World!"

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "nodejs/express"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "nodejs/express"

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "nodejs/express"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "nodejs/express"

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e;
set -e
test_url () {
test_url() {
path="$1"
expected_output="$2"
url="${base_url}:3000${path}"

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -ex;
set -ex
REMOTE=$1
REPO=$2

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello World!"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "Hello World!"

View File

@@ -1,2 +1,3 @@
#!/usr/bin/env bash
set -e; test "$(curl -s -S "$1")" == "go"
set -e
test "$(curl -s -S "$1")" == "go"

View File

@@ -1,2 +1,3 @@
#!/usr/bin/env bash
set -e; test "$(curl -s -S "$1")" == "go"
set -e
test "$(curl -s -S "$1")" == "go"

View File

@@ -1,2 +1,3 @@
#!/usr/bin/env bash
set -e; test "$(curl -s -S "$1")" == "go"
set -e
test "$(curl -s -S "$1")" == "go"

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello from Java!"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "Hello from Java!"

View File

@@ -1,2 +1,3 @@
#!/usr/bin/env bash
set -e; curl -s -S "$1" | grep -q "Heroku Multi Buildpack on Dokku"
set -e
curl -s -S "$1" | grep -q "Heroku Multi Buildpack on Dokku"

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "nodejs/express"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "nodejs/express"

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "nodejs/express"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "nodejs/express"

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(pgrep -f "node worker.js" | wc -l)"; echo "$output"; test "$output" == "1"
set -e
output="$(pgrep -f "node worker.js" | wc -l)"
echo "$output"
test "$output" == "1"

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "<html><h3>php</h3></html>"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "<html><h3>php</h3></html>"

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e;
set -e
base_url=$1
test_url () {
test_url() {
path="$1"
expected_output="$2"
url="${base_url}${path}"

View File

@@ -1,5 +1,5 @@
#!/usr/bin/env bash
set -ex;
set -ex
REMOTE=$1
REPO=$2

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello, world"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "Hello, world"

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "Hello from Scala!"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "Hello from Scala!"

View File

@@ -1,2 +1,5 @@
#!/usr/bin/env bash
set -e; output="$(curl -s -S "$1")"; echo "$output"; test "$output" == "<html><h3>Static Page</h3></html>"
set -e
output="$(curl -s -S "$1")"
echo "$output"
test "$output" == "<html><h3>Static Page</h3></html>"

View File

@@ -46,7 +46,7 @@ main() {
TMP_OUTPUT=$(mktemp "/tmp/${FUNCNAME[0]}.XXXX")
trap 'rm -rf "$TMP_OUTPUT" > /dev/null' RETURN INT TERM EXIT
/usr/local/libexec/bats-preprocess < "$TEST_FILE" > "$TMP_OUTPUT"
/usr/local/libexec/bats-preprocess <"$TEST_FILE" >"$TMP_OUTPUT"
AVAILABLE_TESTS="$(fn-available-tests "$TMP_OUTPUT")"
MATCHED_TEST=$(fn-matched-test "$TEST_NAME" "$AVAILABLE_TESTS")

View File

@@ -45,12 +45,12 @@ install_dokku() {
"${ROOT_DIR}/contrib/release" build
echo "dokku dokku/hostname string dokku.me" | sudo debconf-set-selections
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
echo "dokku dokku/skip_key_file boolean true" | sudo debconf-set-selections
echo "dokku dokku/vhost_enable boolean true" | sudo debconf-set-selections
echo "dokku dokku/web_config boolean false" | sudo debconf-set-selections
echo "dokku dokku/nginx_enable boolean true" | sudo debconf-set-selections
echo "dokku dokku/skip_key_file boolean true" | sudo debconf-set-selections
echo "dokku dokku/vhost_enable boolean true" | sudo debconf-set-selections
echo "dokku dokku/web_config boolean false" | sudo debconf-set-selections
sudo dpkg -i "$(cat "${ROOT_DIR}/build/deb-filename")"
}

View File

@@ -1,7 +1,8 @@
#!/usr/bin/env bash
is_number() {
local NUMBER=$1; local NUM_RE='^[1-4]+$'
local NUMBER=$1
local NUM_RE='^[1-4]+$'
if [[ $NUMBER =~ $NUM_RE ]]; then
return 0
else
@@ -33,6 +34,6 @@ for test in $TESTS; do
fi
endtest=$(date +%s)
testruntime=$((endtest-starttest))
testruntime=$((endtest - starttest))
echo "individual runtime: $(date -u -d @${testruntime} +"%T")"
done

View File

@@ -1,7 +1,11 @@
#!/usr/bin/env bash
set -xeo pipefail
SELF=$(which "$0"); APP="$1"; TARGET="$2"; FORWARDED_PORT="$3"; SHOULD_FAIL="$4"
SELF=$(which "$0")
APP="$1"
TARGET="$2"
FORWARDED_PORT="$3"
SHOULD_FAIL="$4"
REMOTE="dokku@$TARGET"
REPO="test-$(basename "$APP")-$RANDOM"
@@ -25,7 +29,7 @@ succeeded() {
TMP=$(mktemp -d "/tmp/$TARGET.XXXXX")
rmdir "$TMP" && cp -r "$(dirname "$SELF")/$APP" "$TMP"
pushd "$TMP" &> /dev/null || exit 1
pushd "$TMP" &>/dev/null || exit 1
trap 'popd &> /dev/null || true; rm -rf "$TMP"' INT TERM EXIT
git init

View File

@@ -9,7 +9,7 @@ PLUGIN_ENABLED_PATH=${PLUGIN_ENABLED_PATH:="$PLUGIN_PATH/enabled"}
PLUGIN_CORE_PATH=${PLUGIN_CORE_PATH:="$DOKKU_LIB_ROOT/core-plugins"}
PLUGIN_CORE_AVAILABLE_PATH=${PLUGIN_CORE_AVAILABLE_PATH:="$PLUGIN_CORE_PATH/available"}
CUSTOM_TEMPLATE_SSL_DOMAIN=customssltemplate.dokku.me
UUID=$(tr -dc 'a-z0-9' < /dev/urandom | fold -w 32 | head -n 1)
UUID=$(tr -dc 'a-z0-9' </dev/urandom | fold -w 32 | head -n 1)
TEST_APP="rdmtestapp-${UUID}"
TEST_NETWORK="test-network-${UUID}"
SKIPPED_TEST_ERR_MSG="previous test failed! skipping remaining tests..."
@@ -26,8 +26,11 @@ global_teardown() {
# test functions
flunk() {
{ if [[ "$#" -eq 0 ]]; then cat -
else echo "$*"
{
if [[ "$#" -eq 0 ]]; then
cat -
else
echo "$*"
fi
}
return 1
@@ -54,7 +57,8 @@ assert_failure() {
assert_equal() {
if [[ "$1" != "$2" ]]; then
{ echo "expected: $1"
{
echo "expected: $1"
echo "actual: $2"
} | flunk
fi
@@ -81,7 +85,10 @@ assert_output_exists() {
# ShellCheck doesn't know about $output from Bats
# shellcheck disable=SC2154
assert_output_contains() {
local input="$output"; local expected="$1"; local count="${2:-1}"; local found=0
local input="$output"
local expected="$1"
local count="${2:-1}"
local found=0
until [ "${input/$expected/}" = "$input" ]; do
input="${input/$expected/}"
let found+=1
@@ -97,7 +104,7 @@ assert_line() {
else
local line
for line in "${lines[@]}"; do
[[ "$line" = "$1" ]] && return 0
[[ "$line" == "$1" ]] && return 0
done
flunk "expected line \`$1'"
fi
@@ -112,7 +119,7 @@ refute_line() {
else
local line
for line in "${lines[@]}"; do
if [[ "$line" = "$1" ]]; then
if [[ "$line" == "$1" ]]; then
flunk "expected to not find line \`$line'"
fi
done
@@ -131,24 +138,26 @@ assert_exit_status() {
# dokku functions
create_app() {
local APP="$1"; local TEST_APP=${APP:=$TEST_APP}
local APP="$1"
local TEST_APP=${APP:=$TEST_APP}
dokku apps:create "$TEST_APP"
}
create_key() {
ssh-keygen -P "" -f /tmp/testkey &> /dev/null
ssh-keygen -P "" -f /tmp/testkey &>/dev/null
}
destroy_app() {
local RC="$1"; local RC=${RC:=0}
local APP="$2"; local TEST_APP=${APP:=$TEST_APP}
local RC="$1"
local RC=${RC:=0}
local APP="$2"
local TEST_APP=${APP:=$TEST_APP}
dokku --force apps:destroy "$TEST_APP"
return "$RC"
}
destroy_key() {
rm -f /tmp/testkey* &> /dev/null || true
rm -f /tmp/testkey* &>/dev/null || true
}
add_domain() {
@@ -214,7 +223,7 @@ deploy_app() {
# shellcheck disable=SC2086
[[ -n "$CUSTOM_TEMPLATE" ]] && $CUSTOM_TEMPLATE $TEST_APP $TMP/$CUSTOM_PATH
pushd "$TMP" &> /dev/null || exit 1
pushd "$TMP" &>/dev/null || exit 1
trap 'popd &> /dev/null || true; rm -rf "$TMP"' RETURN INT TERM
git init
@@ -243,7 +252,8 @@ setup_client_repo() {
}
setup_test_tls() {
local TLS_TYPE="$1"; local TLS="/home/dokku/$TEST_APP/tls"
local TLS_TYPE="$1"
local TLS="/home/dokku/$TEST_APP/tls"
mkdir -p "$TLS"
case "$TLS_TYPE" in
@@ -262,12 +272,13 @@ setup_test_tls() {
}
custom_ssl_nginx_template() {
local APP="$1"; local APP_REPO_DIR="$2"
local APP="$1"
local APP_REPO_DIR="$2"
[[ -z "$APP" ]] && local APP="$TEST_APP"
mkdir -p "$APP_REPO_DIR"
echo "injecting custom_ssl_nginx_template -> $APP_REPO_DIR/nginx.conf.sigil"
cat<<EOF > "$APP_REPO_DIR/nginx.conf.sigil"
cat <<EOF >"$APP_REPO_DIR/nginx.conf.sigil"
{{ range \$port_map := .PROXY_PORT_MAP | split " " }}
{{ \$port_map_list := \$port_map | split ":" }}
{{ \$scheme := index \$port_map_list 0 }}
@@ -316,16 +327,17 @@ upstream {{ $.APP }}-{{ \$upstream_port }} {
}
{{ end }}{{ end }}
EOF
cat "$APP_REPO_DIR/nginx.conf.sigil"
cat "$APP_REPO_DIR/nginx.conf.sigil"
}
custom_nginx_template() {
local APP="$1"; local APP_REPO_DIR="$2"
local APP="$1"
local APP_REPO_DIR="$2"
[[ -z "$APP" ]] && local APP="$TEST_APP"
mkdir -p "$APP_REPO_DIR"
echo "injecting custom_nginx_template -> $APP_REPO_DIR/nginx.conf.sigil"
cat<<EOF > "$APP_REPO_DIR/nginx.conf.sigil"
cat <<EOF >"$APP_REPO_DIR/nginx.conf.sigil"
{{ range \$port_map := .PROXY_PORT_MAP | split " " }}
{{ \$port_map_list := \$port_map | split ":" }}
{{ \$scheme := index \$port_map_list 0 }}
@@ -362,14 +374,15 @@ upstream {{ $.APP }}-{{ \$upstream_port }} {
}
{{ end }}{{ end }}
EOF
cat "$APP_REPO_DIR/nginx.conf.sigil"
cat "$APP_REPO_DIR/nginx.conf.sigil"
}
bad_custom_nginx_template() {
local APP="$1"; local APP_REPO_DIR="$2"
local APP="$1"
local APP_REPO_DIR="$2"
[[ -z "$APP" ]] && local APP="$TEST_APP"
echo "injecting bad_custom_nginx_template -> $APP_REPO_DIR/nginx.conf.sigil"
cat<<EOF > "$APP_REPO_DIR/nginx.conf.sigil"
cat <<EOF >"$APP_REPO_DIR/nginx.conf.sigil"
some lame nginx config
EOF
}