2024-02-29 20:03:12 +01:00
|
|
|
#!/usr/bin/env bash
|
2020-08-17 17:06:40 +02:00
|
|
|
#
|
|
|
|
# Integration test for remote API
|
|
|
|
#
|
2022-03-15 09:18:01 -04:00
|
|
|
# Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
# SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2020-08-17 17:06:40 +02:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
DIR=$(mktemp -d)
|
|
|
|
pushd ${DIR}
|
2020-08-17 17:06:40 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
function finish {
|
2024-02-29 21:54:10 +01:00
|
|
|
popd
|
|
|
|
rm -rf ${DIR}
|
2021-08-10 10:12:48 -04:00
|
|
|
}
|
|
|
|
trap finish EXIT
|
|
|
|
|
|
|
|
cat > config.json <<EOF
|
2020-08-17 17:06:40 +02:00
|
|
|
{
|
2024-02-29 21:54:10 +01:00
|
|
|
"http": {
|
|
|
|
"port": 8080
|
|
|
|
},
|
|
|
|
"nodes": {
|
|
|
|
"testnode1": {
|
|
|
|
"type": "websocket",
|
|
|
|
"dummy": "value1"
|
|
|
|
},
|
|
|
|
"testnode2": {
|
|
|
|
"type": "socket",
|
|
|
|
"dummy": "value2",
|
2020-08-17 17:06:40 +02:00
|
|
|
|
2024-02-29 21:54:10 +01: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"
|
|
|
|
}
|
|
|
|
]
|
2020-08-17 17:06:40 +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 &
|
2020-08-17 17:06:40 +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/paths > fetched.json
|
2020-08-17 17:06:40 +02:00
|
|
|
|
|
|
|
# Shutdown VILLASnode
|
|
|
|
kill $!
|
|
|
|
|
|
|
|
# Compare local config with the fetched one
|
2021-08-10 10:12:48 -04:00
|
|
|
jq -e '(.[0].in | index("testnode2")) and (.[0].out | index("testnode1")) and (. | length == 1)' fetched.json > /dev/null
|