From 9198ad4997ea1e070852676a9dd4b55aef596d50 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 17 Aug 2020 17:06:40 +0200 Subject: [PATCH] tests: fix integration tests for new API --- tests/integration/api-capabilities.sh | 4 +- tests/integration/api-config.sh | 4 +- tests/integration/api-nodes.sh | 8 +-- tests/integration/api-paths.sh | 83 +++++++++++++++++++++++++++ tests/integration/api-restart.sh | 17 ++---- tests/integration/api-shutdown.sh | 2 +- tests/integration/api-stress.sh | 4 +- 7 files changed, 98 insertions(+), 24 deletions(-) create mode 100755 tests/integration/api-paths.sh diff --git a/tests/integration/api-capabilities.sh b/tests/integration/api-capabilities.sh index a26a3fc3a..793f38d7a 100755 --- a/tests/integration/api-capabilities.sh +++ b/tests/integration/api-capabilities.sh @@ -34,12 +34,12 @@ PID=$! sleep 1 # Fetch capabilities -echo '{ "action" : "capabilities", "id" : "1" }' | nc -U /usr/local/var/lib/villas/node-*.sock > ${FETCHED_CONF} +curl -s http://localhost:8080/api/v2/capabilities > ${FETCHED_CONF} kill $PID wait -jq -e '.response.apis | index( "capabilities" ) != null' < ${FETCHED_CONF} +jq -e '.apis | index( "capabilities" ) != null' < ${FETCHED_CONF} RC=$? rm ${FETCHED_CONF} diff --git a/tests/integration/api-config.sh b/tests/integration/api-config.sh index aa07bac4e..7da4d3005 100755 --- a/tests/integration/api-config.sh +++ b/tests/integration/api-config.sh @@ -50,13 +50,13 @@ villas-node ${CONFIG_FILE} & sleep 1 # Fetch config via API -curl -sX POST --data '{ "action" : "config", "id" : "'${ID}'" }' http://localhost:8080/api/v1 > ${FETCHED_CONF} +curl -s http://localhost:8080/api/v2/config > ${FETCHED_CONF} # Shutdown VILLASnode kill $! # Compare local config with the fetched one -diff -u <(jq -S .response < ${FETCHED_CONF}) <(jq -S . < ${CONFIG_FILE}) +diff -u <(jq -S . < ${FETCHED_CONF}) <(jq -S . < ${CONFIG_FILE}) RC=$? rm -f ${FETCHED_CONF} ${CONFIG_FILE} diff --git a/tests/integration/api-nodes.sh b/tests/integration/api-nodes.sh index 21fa58731..544e4ef58 100755 --- a/tests/integration/api-nodes.sh +++ b/tests/integration/api-nodes.sh @@ -49,7 +49,7 @@ cat > ${CONFIG_FILE} < ${FETCHED_NODES} - -cat ${FETCHED_NODES} +curl -s http://localhost:8080/api/v2/nodes > ${FETCHED_NODES} # Shutdown VILLASnode kill $! # Compare local config with the fetched one -jq -e '.response[0].name == "testnode1" and .response[0].type == "websocket" and (.response | length == 2)' ${FETCHED_NODES} > /dev/null +jq -e '.[0].name == "testnode1" and .[0].type == "websocket" and (. | length == 2)' ${FETCHED_NODES} > /dev/null RC=$? rm -f ${CONFIG_FILE} ${FETCHED_NODES} diff --git a/tests/integration/api-paths.sh b/tests/integration/api-paths.sh new file mode 100755 index 000000000..709463742 --- /dev/null +++ b/tests/integration/api-paths.sh @@ -0,0 +1,83 @@ +#!/bin/bash +# +# Integration test for remote API +# +# @author Steffen Vogel +# @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC +# @license GNU General Public License (version 3) +# +# VILLASnode +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +################################################################################## + +set -e + +CONFIG_FILE=$(mktemp) +FETCHED_PATHS=$(mktemp) + +cat > ${CONFIG_FILE} < ${FETCHED_PATHS} + +# Shutdown VILLASnode +kill $! + +# Compare local config with the fetched one +jq -e '(.[0].in | index("testnode2")) and (.[0].out | index("testnode1")) and (. | length == 1)' ${FETCHED_PATHS} > /dev/null +RC=$? + +rm -f ${CONFIG_FILE} ${FETCHED_PATHS} + +exit $RC diff --git a/tests/integration/api-restart.sh b/tests/integration/api-restart.sh index 7509e0794..12500b280 100755 --- a/tests/integration/api-restart.sh +++ b/tests/integration/api-restart.sh @@ -58,34 +58,27 @@ cat < ${LOCAL_CONF} } EOF -cat < ${BASE_CONF} -{ - "http" : { - "port" : 8080 - } -} -EOF - # Start with base configuration -villas-node ${BASE_CONF} & +villas-node & # Wait for node to complete init sleep 1 # Restart with configuration -curl -sX POST --data '{ "action" : "restart", "request" : { "config": "'${LOCAL_CONF}'" }, "id" : "5a786626-fbc6-4c04-98c2-48027e68c2fa" }' http://localhost:8080/api/v1 +curl -sX POST --data '{ "config": "'${LOCAL_CONF}'" }' http://localhost:8080/api/v2/restart +echo # Wait for node to complete init sleep 2 # Fetch config via API -curl -sX POST --data '{ "action" : "config", "id" : "5a786626-fbc6-4c04-98c2-48027e68c2fa" }' http://localhost:8080/api/v1 > ${FETCHED_CONF} +curl -s http://localhost:8080/api/v2/config > ${FETCHED_CONF} # Shutdown VILLASnode kill %% # Compare local config with the fetched one -diff -u <(jq -S .response < ${FETCHED_CONF}) <(jq -S . < ${LOCAL_CONF}) +diff -u <(jq -S . < ${FETCHED_CONF}) <(jq -S . < ${LOCAL_CONF}) RC=$? rm -f ${LOCAL_CONF} ${FETCHED_CONF} ${BASE_CONF} diff --git a/tests/integration/api-shutdown.sh b/tests/integration/api-shutdown.sh index a8915d86e..d21dadf0a 100755 --- a/tests/integration/api-shutdown.sh +++ b/tests/integration/api-shutdown.sh @@ -41,7 +41,7 @@ timeout -s SIGKILL 3 villas-node ${CONFIG_FILE} & sleep 1 # Restart with configuration -curl -sX POST --data '{ "action" : "shutdown", "id" : "5a786626-fbc6-4c04-98c2-48027e68c2fa" }' http://localhost:8080/api/v1 +curl -sX POST http://localhost:8080/api/v2/shutdown rm ${CONFIG_FILE} diff --git a/tests/integration/api-stress.sh b/tests/integration/api-stress.sh index 4820259a7..db3a7bc73 100755 --- a/tests/integration/api-stress.sh +++ b/tests/integration/api-stress.sh @@ -56,8 +56,8 @@ for J in $(seq 1 ${RUNS}); do FETCHED_CONF=$(mktemp) - curl -sX POST --data '{ "action" : "config", "id" : "'$(uuidgen)'" }' http://localhost:8080/api/v1 > ${FETCHED_CONF} - diff -u <(jq -S .response < ${FETCHED_CONF}) <(jq -S . < ${LOCAL_CONF}) + curl -s http://localhost:8080/api/v2/config > ${FETCHED_CONF} + diff -u <(jq -S . < ${FETCHED_CONF}) <(jq -S . < ${LOCAL_CONF}) RC=$? if [ "$RC" -eq "0" ]; then