From 00403b958509f183995011051bc273fc19296b2f Mon Sep 17 00:00:00 2001 From: Matthias Kruk Date: Fri, 10 Sep 2021 07:02:02 +0900 Subject: [PATCH] publish_test: Add script for publishing test results There is currently no way to manually publish a test message, making it necessary to run a test on a testbot instance in order to test the behavior of dispatchbot. This commit adds a script that allows the caller to publish a test message without the need to run a testbot instance. --- publish_test.sh | 78 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100755 publish_test.sh diff --git a/publish_test.sh b/publish_test.sh new file mode 100755 index 0000000..3f7fc59 --- /dev/null +++ b/publish_test.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +publish_test_result() { + local context="$1" + local repository="$2" + local result="$3" + local branch="$4" + + local message + local endpoint + local err + + err=0 + + if ! message=$(foundry_msg_test_new "$context" \ + "$repository" \ + "$branch" \ + "$result"); then + log_error "Could not create test message" + return 1 + fi + + if ! endpoint=$(ipc_endpoint_open); then + log_error "Could not open IPC endpoint" + return 1 + fi + + if ! ipc_endpoint_publish "$endpoint" "tests" "$message"; then + log_error "Could not publish test result" + err=1 + fi + + if ! ipc_endpoint_close "$endpoint"; then + log_error "Could not close IPC endpoint" + fi + + return "$err" +} + +main() { + local context + local repository + local result + local branch + + opt_add_arg "c" "context" "rv" "" "The context the test was performed in" + opt_add_arg "r" "repository" "rv" "" "The repository that was tested" + opt_add_arg "e" "result" "rv" 0 "The result of the test" + opt_add_arg "b" "branch" "rv" "" "The branch that was tested" + + if ! opt_parse "$@"; then + return 1 + fi + + context=$(opt_get "context") + repository=$(opt_get "repository") + result=$(opt_get "result") + branch=$(opt_get "branch") + + if ! publish_test_result "$context" "$repository" "$result" "$branch"; then + return 1 + fi + + return 0 +} + +{ + if ! . toolbox.sh; then + exit 1 + fi + + if ! include "log" "opt" "ipc" "foundry/msg"; then + exit 1 + fi + + main "$@" + exit "$?" +} -- 2.47.3