Skip to content

Commit 7be98e1

Browse files
committed
even better node_list implementation
1 parent d99a03e commit 7be98e1

4 files changed

Lines changed: 16 additions & 20 deletions

File tree

ci/helper.sh

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,17 @@ function get_nodes() {
7474
function get_status() {
7575
local servise="$1"
7676
local port="$(amoc_container_port "$servise")"
77-
echo -e "\nstatus ${1}:" >/dev/tty
78-
curl -s -X GET "http://localhost:${port}/status" -H "accept: application/json" | tee /dev/tty
79-
echo -e "\n" >/dev/tty
77+
curl -s -X GET "http://localhost:${port}/status" -H "accept: application/json"
78+
}
79+
80+
function json_list() {
81+
jq -n -c --args '$ARGS.positional' "$@"
8082
}
8183

8284
function node_list() {
83-
local nodes_json="" node=""
84-
if [ "$#" -gt "0" ]; then
85-
nodes_json+='"nodes": ["'"$1"'"'
86-
shift 1
87-
for node in "$@"; do
88-
nodes_json+=', "'"$node"'"'
89-
done
90-
nodes_json+='], '
85+
if [ "$#" -gt '0' ]; then
86+
echo "\"nodes\": $(json_list "$@"), "
9187
fi
92-
echo -n "$nodes_json"
9388
}
9489

9590
#################################

ci/test_add_and_remove_users.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ function add_users() {
1111
local port="$(amoc_container_port "$1")" # $1 - where to send request
1212
local n="$2" # $2 - number of users to add
1313
shift 2
14-
local nodes="$(node_list "$@")"
15-
local json_body="{ ${nodes} \"users\": $n}"
14+
local maybe_nodes="$(node_list "$@")"
15+
local json_body="{ ${maybe_nodes} \"users\": ${n}}"
16+
echo "${json_body}" >&2
1617
curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' \
1718
-s -w " %{http_code}" -d "$json_body" "http://localhost:${port}/execution/add_users"
1819
}
@@ -21,8 +22,9 @@ function remove_users() {
2122
local port="$(amoc_container_port "$1")" # $1 - where to send request
2223
local n="$2" # $2 - number of users to add
2324
shift 2
24-
local nodes="$(node_list "$@")"
25-
local json_body="{ ${nodes} \"users\": $n}"
25+
local maybe_nodes="$(node_list "$@")"
26+
local json_body="{ ${maybe_nodes} \"users\": ${n}}"
27+
echo "${json_body}" >&2
2628
curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' \
2729
-s -w " %{http_code}" -d "$json_body" "http://localhost:${port}/execution/remove_users"
2830
}

ci/test_run_scenario.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ enable_strict_mode
88
#############################
99
run_scenario() {
1010
local port="$(amoc_container_port "$1")"
11-
local json_body='{ "scenario": "'"$2"'", "users": '"$3"' , "settings" : { "test" : "<<\"test_value\">>" } }'
11+
local json_body='{ "scenario": "'"$2"'", "users": '"$3"', "settings" : { "test" : "<<\"test_value\">>" } }'
1212
curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' \
1313
-s -w "%{http_code}" -o /dev/null -d "$json_body" "http://localhost:${port}/execution/start"
1414
}

ci/test_update_settings.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ function update_settings() {
1111
local port="$(amoc_container_port "$1")" # $1 - where to send request
1212
local settings="$2" # $2 - settings
1313
shift 2
14-
local nodes="$(node_list "$@")"
15-
local json_body="{ ${nodes} \"settings\": ${settings} }"
16-
echo "json_body = '$json_body'" >&2
14+
local maybe_nodes="$(node_list "$@")"
15+
local json_body="{ ${maybe_nodes} \"settings\": ${settings} }"
1716
curl -X PATCH --header 'Content-Type: application/json' --header 'Accept: application/json' \
1817
-s -w " %{http_code}" -d "$json_body" "http://localhost:${port}/execution/update_settings"
1918
}

0 commit comments

Comments
 (0)