Skip to content

Commit

Permalink
example: Add system tests for microd/microctl
Browse files Browse the repository at this point in the history
Signed-off-by: Wesley Hershberger <[email protected]>
  • Loading branch information
MggMuggins committed Apr 22, 2024
1 parent 05982b6 commit c4cf5dc
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Misc test files
example/test/system
4 changes: 2 additions & 2 deletions example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ check-unit:
go test ./...

.PHONY: check-system
check-system:
true
check-system: build
./test/main.sh

.PHONY: check-static
check-static:
Expand Down
6 changes: 6 additions & 0 deletions example/test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# Environment variables
Name | Default | Description
:-- | :-- | :--
`DEBUG` | "" | Sets `set -x`
`CLUSTER_INSPECT` | "" | Any `microd` processes are not killed when `main.sh` exits
35 changes: 35 additions & 0 deletions example/test/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

if [ -n "${DEBUG:-}" ]; then
set -x
fi

test_dir="$(realpath -e "$(dirname -- "${BASH_SOURCE[0]}")")/system"

if [ -d "${test_dir}" ]; then
rm -r "${test_dir}"
fi

members=("c1" "c2" "c3")

for member in "${members[@]}"; do
state_dir="${test_dir}/${member}"
mkdir -p "${state_dir}"
microd --state-dir "${state_dir}" &
microctl --state-dir "${state_dir}" waitready
done

microctl --state-dir "${test_dir}/c1" init "c1" 127.0.0.1:9001 --bootstrap

token_node2=$(microctl --state-dir "${test_dir}/c1" tokens add "c2")
token_node3=$(microctl --state-dir "${test_dir}/c1" tokens add "c3")

microctl --state-dir "${test_dir}/c2" init "c2" 127.0.0.1:9002 --token "${token_node2}"
microctl --state-dir "${test_dir}/c3" init "c3" 127.0.0.1:9003 --token "${token_node3}"

# Clean up
if [ -z "${CLUSTER_INSPECT:-}" ]; then
kill %1
kill %2
kill %3
fi

0 comments on commit c4cf5dc

Please sign in to comment.