aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-03-12 16:46:43 +0100
committerEgor Tensin <Egor.Tensin@gmail.com>2023-03-12 16:53:37 +0100
commit897e8a30ed5b292df9d987f5f566e58a71394ce9 (patch)
tree16105ac99a07d1e3cd95d32a0cdc874fc9154347
parenttest: add more headers to logs (diff)
downloadwg-api-web-897e8a30ed5b292df9d987f5f566e58a71394ce9.tar.gz
wg-api-web-897e8a30ed5b292df9d987f5f566e58a71394ce9.zip
test: refactoring
In preparation to adding LinuxServer tests.
Diffstat (limited to '')
-rw-r--r--.github/workflows/ci.yml2
-rwxr-xr-xtest/check_api.sh33
-rwxr-xr-xtest/host/test.sh (renamed from test/test.sh)57
3 files changed, 38 insertions, 54 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index bf34bae..3f229d2 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -15,7 +15,7 @@ jobs:
- name: Install dependencies
run: sudo apt install -y wireguard-tools
- name: Test
- run: sudo ./test/test.sh
+ run: sudo ./test/host/test.sh
publish:
needs: [test]
diff --git a/test/check_api.sh b/test/check_api.sh
new file mode 100755
index 0000000..4dcc199
--- /dev/null
+++ b/test/check_api.sh
@@ -0,0 +1,33 @@
+#!/usr/bin/env bash
+
+set -o errexit -o nounset -o pipefail
+shopt -s inherit_errexit lastpipe
+
+run_curl() {
+ curl -sS -D - --connect-timeout 3 http://192.168.177.1:1234/ "$@"
+}
+
+run_curl_api() {
+ run_curl -H 'Content-Type: application/json' "$@"
+}
+
+call_api_method() {
+ local method
+ for method; do
+ echo ------------------------------------------------------------------
+ echo "Checking API method: $method"
+ echo ------------------------------------------------------------------
+ run_curl_api -d '{"jsonrpc": "2.0", "method": "'"$method"'", "params": {}}'
+ done
+}
+
+check_api() {
+ call_api_method ListPeers
+ call_api_method GetDeviceInfo
+}
+
+main() {
+ check_api
+}
+
+main "$@"
diff --git a/test/test.sh b/test/host/test.sh
index c8839bb..25d5a87 100755
--- a/test/test.sh
+++ b/test/host/test.sh
@@ -7,8 +7,6 @@ script_dir="$( dirname -- "${BASH_SOURCE[0]}" )"
script_dir="$( cd -- "$script_dir" && pwd )"
readonly script_dir
-devices_only=
-
base_dir="$( mktemp -d )"
readonly base_dir
@@ -116,29 +114,6 @@ build_services() {
WG_IFACE=server docker-compose up -d
}
-run_curl() {
- curl -sS -D - --connect-timeout 3 http://192.168.177.1:1234/ "$@"
-}
-
-run_curl_api() {
- run_curl -H 'Content-Type: application/json' "$@"
-}
-
-call_api_method() {
- local method
- for method; do
- echo ------------------------------------------------------------------
- echo "Checking API method: $method"
- echo ------------------------------------------------------------------
- run_curl_api -d '{"jsonrpc": "2.0", "method": "'"$method"'", "params": {}}'
- done
-}
-
-check_api() {
- call_api_method ListPeers
- call_api_method GetDeviceInfo
-}
-
cleanup() {
echo ------------------------------------------------------------------
echo Cleaning up
@@ -156,41 +131,17 @@ cleanup() {
echo "Removing $base_dir"
rm -rf -- "$base_dir"
- if [ -z "$devices_only" ]; then
- echo "Brining down containers..."
- docker-compose down -v --remove-orphans
- fi
+ echo "Brining down containers..."
+ docker-compose down -v --remove-orphans
}
main() {
cd -- "$script_dir/.."
trap cleanup EXIT
- local opt
- while getopts ':i' opt "$@"; do
- case "$opt" in
- i)
- devices_only=1
- ;;
- :)
- echo "usage error: required argument missing for option -$OPTARG" >&2
- exit 1;
- ;;
- *)
- echo "usage error: invalid option -$OPTARG" >&2;
- exit 1;
- ;;
- esac
- done
-
add_devices
-
- if [ -z "$devices_only" ]; then
- build_services
- check_api
- else
- while true; do sleep 1; done
- fi
+ build_services
+ "$script_dir/../check_api.sh"
}
main "$@"