mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
tests: fix integration tests for new API
This commit is contained in:
parent
c48e6718dc
commit
9198ad4997
7 changed files with 98 additions and 24 deletions
|
@ -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}
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -49,7 +49,7 @@ cat > ${CONFIG_FILE} <<EOF
|
|||
]
|
||||
},
|
||||
"out" : {
|
||||
"address" : "localhost:12000"
|
||||
"address" : "127.0.0.1:12000"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -69,15 +69,13 @@ villas-node ${CONFIG_FILE} &
|
|||
sleep 1
|
||||
|
||||
# Fetch config via API
|
||||
curl -sX POST --data '{ "action" : "nodes", "id" : "5a786626-fbc6-4c04-98c2-48027e68c2fa" }' http://localhost:8080/api/v1 > ${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}
|
||||
|
|
83
tests/integration/api-paths.sh
Executable file
83
tests/integration/api-paths.sh
Executable file
|
@ -0,0 +1,83 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Integration test for remote API
|
||||
#
|
||||
# @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
||||
# @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 <http://www.gnu.org/licenses/>.
|
||||
##################################################################################
|
||||
|
||||
set -e
|
||||
|
||||
CONFIG_FILE=$(mktemp)
|
||||
FETCHED_PATHS=$(mktemp)
|
||||
|
||||
cat > ${CONFIG_FILE} <<EOF
|
||||
{
|
||||
"http" : {
|
||||
"port" : 8080
|
||||
},
|
||||
"nodes" : {
|
||||
"testnode1" : {
|
||||
"type" : "websocket",
|
||||
"dummy" : "value1"
|
||||
},
|
||||
"testnode2" : {
|
||||
"type" : "socket",
|
||||
"dummy" : "value2",
|
||||
|
||||
"in" : {
|
||||
"address" : "*:12001",
|
||||
"signals" : [
|
||||
{ "name": "sig1", "unit": "Volts", "type": "float", "init": 123.0 },
|
||||
{ "name": "sig2", "unit": "Ampere", "type": "integer", "init": 123 }
|
||||
]
|
||||
},
|
||||
"out" : {
|
||||
"address" : "127.0.0.1:12000"
|
||||
}
|
||||
}
|
||||
},
|
||||
"paths": [
|
||||
{
|
||||
"in": "testnode2",
|
||||
"out": "testnode1"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
# Start VILLASnode instance with local config (via advio)
|
||||
villas-node ${CONFIG_FILE} &
|
||||
|
||||
# Wait for node to complete init
|
||||
sleep 1
|
||||
|
||||
# Fetch config via API
|
||||
curl -s http://localhost:8080/api/v2/paths > ${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
|
|
@ -58,34 +58,27 @@ cat <<EOF > ${LOCAL_CONF}
|
|||
}
|
||||
EOF
|
||||
|
||||
cat <<EOF > ${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}
|
||||
|
|
|
@ -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}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue