Skip to content

Commit

Permalink
unify all test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Dec 12, 2023
1 parent 0212984 commit 3e67380
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 75 deletions.
2 changes: 2 additions & 0 deletions build_cloudflare.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

set -xe
poetry install
poetry run -- mkdocs build
3 changes: 3 additions & 0 deletions devcontainer/nix-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ set +e
if ! pidof nix-daemon > /dev/null 2>&1; then
start_ok=false
if [ "$(id -u)" = "0" ]; then
# shellcheck source=/dev/null
( . /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh; /nix/var/nix/profiles/default/bin/nix-daemon > /tmp/nix-daemon.log 2>&1 ) &
# shellcheck disable=SC2181
if [ "$?" = "0" ]; then
start_ok=true
fi
elif type sudo > /dev/null 2>&1; then
sudo -n sh -c '. /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh; /nix/var/nix/profiles/default/bin/nix-daemon > /tmp/nix-daemon.log 2>&1' &
# shellcheck disable=SC2181
if [ "$?" = "0" ]; then
start_ok=true
fi
Expand Down
18 changes: 15 additions & 3 deletions examples/clickhouse/.test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
#!/bin/sh
#!/usr/bin/env bash

set -ex
pkill clickhouse
devenv up&

devenv up &
DEVENV_PID=$!
export DEVENV_PID

devenv_stop() {
pkill -P "$DEVENV_PID"
}

trap devenv_stop EXIT

timeout 20 bash -c 'until echo > /dev/tcp/localhost/9000; do sleep 0.5; done'
sleep 2

clickhouse-client --query "SELECT 1"
1 change: 1 addition & 0 deletions examples/cockroachdb/devenv.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
allowUnfree: true
inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixpkgs-unstable
2 changes: 2 additions & 0 deletions examples/dotenv/.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

env | grep FOO=1
env | grep BAR=1
env | grep BAZ=5
2 changes: 2 additions & 0 deletions examples/fly.io/.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

if [ "$(uname -s)" == "Linux" ]; then
devenv container shell
devenv container processes
Expand Down
3 changes: 2 additions & 1 deletion examples/gleam/.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

set -ex
gleam --version
2 changes: 2 additions & 0 deletions examples/imports/.test.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#!/usr/bin/env bash

env | grep "FILE=1"
env | grep "FOLDER=1"
3 changes: 2 additions & 1 deletion examples/javascript/.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

set -ex
node -e "require('axios')"
3 changes: 2 additions & 1 deletion examples/jsonnet/.test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

set -ex
jsonnet --version
10 changes: 8 additions & 2 deletions examples/minio/.test.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex

devenv up &
DEVENV_PID=$!
trap "pkill -P $DEVENV_PID" EXIT
export DEVENV_PID

devenv_stop() {
pkill -P "$DEVENV_PID"
}

trap devenv_stop EXIT

timeout 20 bash -c 'until echo > /dev/tcp/localhost/9000; do sleep 0.5; done'

Expand Down
10 changes: 8 additions & 2 deletions examples/mysql/.test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex

devenv up &
DEVENV_PID=$!
trap "pkill -P $DEVENV_PID" EXIT
export DEVENV_PID

devenv_stop() {
pkill -P "$DEVENV_PID"
}

trap devenv_stop EXIT

timeout 60 bash -c 'until MYSQL_PWD="" mysql -u root test_database < /dev/null; do sleep 0.5; done'
2 changes: 1 addition & 1 deletion examples/phoenix/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex
mix local.hex --force
mix local.rebar --force
Expand Down
2 changes: 1 addition & 1 deletion examples/postgres-timescale/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex
devenv up&
timeout 20 bash -c 'until psql -c "SELECT 1" mydb; do sleep 0.5; done'
2 changes: 1 addition & 1 deletion examples/postgres/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex

devenv up &
Expand Down
2 changes: 1 addition & 1 deletion examples/python-poetry/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -exu
POETRY_VENV="$PWD/.venv"
[ -d "$POETRY_VENV" ]
Expand Down
2 changes: 1 addition & 1 deletion examples/python-venv/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex
[ "$(command -v python)" = "$PWD/.devenv/state/venv/bin/python" ]
[ "$VIRTUAL_ENV" = "$PWD/.devenv/state/venv" ]
Expand Down
2 changes: 1 addition & 1 deletion examples/python/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex
python --version | grep "3.11.3"
python -c "import requests;print(requests)"
2 changes: 1 addition & 1 deletion examples/ruby/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex
ruby --version | grep "$(cat .ruby-version)"
ruby -e "puts RUBY_VERSION" | grep "$(cat .ruby-version)"
Expand Down
2 changes: 1 addition & 1 deletion examples/rubyonrails/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex
rails new blog -d=postgresql
devenv up&
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex
cargo --version
rustc --version
Expand Down
2 changes: 1 addition & 1 deletion examples/shell/.test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash
set -ex
bash-language-server --version
bats --version
Expand Down
1 change: 1 addition & 0 deletions examples/supported-languages/devenv.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
allowUnfree: true
inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixpkgs-unstable
42 changes: 16 additions & 26 deletions examples/temporal/.test.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
#!/bin/sh
#!/usr/bin/env bash
set -x

# Start the services in the background and store the PID
echo "Starting temporal service..."
devenv up &
DEVENV_PID=$!
export DEVENV_PID

devenv_stop() {
pkill -P "$DEVENV_PID"
}

trap devenv_stop EXIT

export TEMPORAL_ADDRESS=127.0.0.1:17233

# temporal status and store its exit status
check_temporal_status() {
echo "Waiting for service to become available..."
TEMPORAL_OUTPUT=$(temporal operator cluster health)
TEMPORAL_EXIT_STATUS=$?
}
timeout 20 bash -c 'until echo > /dev/tcp/localhost/17233; do sleep 0.5; done'

# Continuously check temporal status until it returns successfully (up to a maximum of 20 times)
for i in $(seq 1 20); do
check_temporal_status
if [ $TEMPORAL_EXIT_STATUS -eq 0 ]; then
echo "Service is up..."
break
else
sleep 1
fi
done
sleep 1

if ! temporal operator cluster health; then
echo "Temporal not started"
exit 1
fi

echo "Checking namespace..."
temporal operator namespace describe mynamespace

# Print the captured output when temporal status succeeds
echo "Startup complete..."
temporal operator cluster system
echo "$TEMPORAL_OUTPUT"

# Clean up by terminating all spawned processes
pkill -P $DEVENV_PID
wait $DEVENV_PID&>/dev/null

# Exit the script
exit $TEMPORAL_EXIT_STATUS
echo "$TEMPORAL_OUTPUT"
8 changes: 7 additions & 1 deletion examples/varnish/.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ set -ex

devenv up &
DEVENV_PID=$!
trap "pkill -P $DEVENV_PID" EXIT
export DEVENV_PID

devenv_stop() {
pkill -P "$DEVENV_PID"
}

trap devenv_stop EXIT

timeout 20 bash -c 'until echo > /dev/tcp/localhost/6081; do sleep 0.5; done'

Expand Down
2 changes: 1 addition & 1 deletion examples/varnish/devenv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
services.varnish = {
enable = true;
package = pkgs.varnish73;
package = pkgs.varnish;
vcl = ''
vcl 4.0;
Expand Down
37 changes: 10 additions & 27 deletions examples/vault/.test.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
#!/bin/sh
#!/usr/bin/env bash
set -x

# Start the services in the background and store the PID
echo "Starting vault service..."
devenv up&
devenv up &
DEVENV_PID=$!
export DEVENV_PID

# vault status and store its exit status
check_vault_status() {
echo "Waiting for service to become available..."
VAULT_OUTPUT=$(vault status 2>&1)
VAULT_EXIT_STATUS=$?
# shellcheck disable=SC2317 # ShellCheck may incorrectly believe that code is unreachable if it's invoked by variable name or in a trap
devenv_stop() {
pkill -P "$DEVENV_PID"
}

# Continuously check vault status until it returns successfully (up to a maximum of 100 times)
for i in $(seq 1 20); do
check_vault_status
if [ $VAULT_EXIT_STATUS -eq 0 ]; then
echo "Service is up..."
break
else
sleep 1
fi
done
trap devenv_stop EXIT

# Print the captured output when vault status succeeds
echo "Startup complete..."
vault version
echo "$VAULT_OUTPUT"
timeout 20 bash -c 'until echo > /dev/tcp/localhost/8200; do sleep 0.5; done'

# Clean up by terminating all spawned processes
pkill -P $DEVENV_PID
wait $DEVENV_PID &> /dev/null
vault status

# Exit the script
exit $VAULT_EXIT_STATUS
exit $?
1 change: 1 addition & 0 deletions examples/vault/devenv.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixpkgs-unstable
allowUnfree: true

0 comments on commit 3e67380

Please sign in to comment.