2025-01-14 14:42:39 +00:00
|
|
|
#!/usr/bin/env bash
|
2017-04-27 13:08:17 +02:00
|
|
|
#
|
|
|
|
# Integration test for remote API
|
|
|
|
#
|
2025-01-14 14:42:39 +00:00
|
|
|
# Author: Steffen Vogel <post@steffenvogel.de>
|
|
|
|
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2017-04-02 13:03:49 +02:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
DIR=$(mktemp -d)
|
|
|
|
pushd ${DIR}
|
2017-04-02 13:03:49 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
function finish {
|
2025-01-14 14:42:39 +00:00
|
|
|
popd
|
|
|
|
rm -rf ${DIR}
|
2021-08-10 10:12:48 -04:00
|
|
|
}
|
|
|
|
trap finish EXIT
|
|
|
|
|
|
|
|
|
|
|
|
cat > config.json <<EOF
|
2017-08-03 00:21:56 +02:00
|
|
|
{
|
2025-01-14 14:42:39 +00:00
|
|
|
"http": {
|
|
|
|
"port": 8080
|
|
|
|
},
|
|
|
|
"nodes": {
|
|
|
|
"testnode1": {
|
|
|
|
"type": "websocket",
|
|
|
|
"dummy": "value1"
|
|
|
|
},
|
|
|
|
"testnode2": {
|
|
|
|
"type": "socket",
|
|
|
|
"dummy": "value2",
|
2017-05-05 19:24:16 +00:00
|
|
|
|
2025-01-14 14:42:39 +00:00
|
|
|
"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"
|
|
|
|
}
|
|
|
|
]
|
2017-04-02 13:03:49 +02:00
|
|
|
}
|
|
|
|
EOF
|
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
# Start VILLASnode instance with local config
|
2021-08-10 10:12:48 -04:00
|
|
|
villas node config.json &
|
2017-04-02 13:03:49 +02:00
|
|
|
|
|
|
|
# Wait for node to complete init
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
# Fetch config via API
|
2021-08-10 10:12:48 -04:00
|
|
|
curl -s http://localhost:8080/api/v2/nodes > fetched.json
|
2020-07-01 17:02:53 +02:00
|
|
|
|
2017-04-02 13:03:49 +02:00
|
|
|
# Shutdown VILLASnode
|
|
|
|
kill $!
|
|
|
|
|
|
|
|
# Compare local config with the fetched one
|
2021-08-10 10:12:48 -04:00
|
|
|
jq -e '.[0].name == "testnode1" and .[0].type == "websocket" and (. | length == 2)' fetched.json > /dev/null
|