]> git.corax.cc Git - foundry/commitdiff
publish_test: Add script for publishing test results
authorMatthias Kruk <m@m10k.eu>
Thu, 9 Sep 2021 22:02:02 +0000 (07:02 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 9 Sep 2021 22:02:02 +0000 (07:02 +0900)
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 [new file with mode: 0755]

diff --git a/publish_test.sh b/publish_test.sh
new file mode 100755 (executable)
index 0000000..3f7fc59
--- /dev/null
@@ -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 "$?"
+}