62 lines
1.6 KiB
Bash
Executable file
62 lines
1.6 KiB
Bash
Executable file
TMPDIR=$(mktemp -d)
|
|
|
|
trap "rm -fr $TMPDIR" EXIT
|
|
|
|
source $EXAMPLE_DIR/../../lib/lib.sh
|
|
|
|
export d=/srv/example/tag
|
|
context=/srv/example/workflow-dispatch/contexts/workflow_dispatch/github
|
|
api=$url/api/v1
|
|
repo=root/example-$example
|
|
|
|
function context_wait() {
|
|
if ! forgejo.sh retry test -f $context; then
|
|
cat "$FORGEJO_RUNNER_LOGS"
|
|
false
|
|
fi
|
|
}
|
|
|
|
function verify_required() {
|
|
local actual=$(forgejo-curl.sh api_json -w '%{http_code}' --data '{"ref":"main","inputs":{}}' $api/repos/$repo/actions/workflows/test.yml/dispatches)
|
|
local expected=400
|
|
if test "$actual" != $expected; then
|
|
log_info "dispatch is expected to fail with status $expected because of string2 is a required value but got status $actual instead"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
function verify_inputs() {
|
|
local inputs='{"string2":"value2"}'
|
|
forgejo-curl.sh api_json --data '{"ref":"main","inputs":'$inputs'}' $api/repos/$repo/actions/workflows/test.yml/dispatches
|
|
cat >$TMPDIR/expected <<'EOF'
|
|
{
|
|
"boolean_default_false": "false",
|
|
"boolean_default_true": "true",
|
|
"logLevel": "warning",
|
|
"number1_default": "100",
|
|
"string1_default": "Hello world",
|
|
"string2": "value2"
|
|
}
|
|
EOF
|
|
}
|
|
|
|
function run_tests() {
|
|
verify_required
|
|
|
|
npm --silent install json-diff
|
|
verify_inputs
|
|
context_wait
|
|
node_modules/.bin/json-diff <(jq .event.inputs <$context) $TMPDIR/expected
|
|
}
|
|
|
|
function main() {
|
|
mkdir -p $d
|
|
|
|
forgejo-test-helper.sh push_workflow actions/example-$example $url root example-$example setup-forgejo $token
|
|
|
|
run_tests
|
|
|
|
test "workflow_dispatch" = "$(jq -r .event_name <$context)"
|
|
}
|
|
|
|
main
|