Skip to content

Commit

Permalink
ci: add tests of OpenAPI document with schemathesis
Browse files Browse the repository at this point in the history
  • Loading branch information
flashcode committed May 15, 2024
1 parent 4c56541 commit 6db01be
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ jobs:
weechat --version
weechat --run-command "/debug dirs;/debug libs" --run-command "/quit"
- name: Test Relay OpenAPI
if: ${{ matrix.config.name == 'gcc' }}
env:
RELAY_PASSWORD: test
run: |
sudo -H pip3 install --ignore-installed schemathesis
weechat-headless \
--dir /tmp/weechat-test-api \
--run-command '/set relay.network.password "${{ env.RELAY_PASSWORD }}"' \
--run-command '/relay add api 9000' \
--daemon \
;
sleep 5
./tools/test_relay_api.sh http://localhost:9000
echo '*/quit' >/tmp/weechat-test-api/weechat_fifo_*
- name: Code coverage
if: ${{ matrix.config.name == 'gcc_coverage' }}
env:
Expand Down
86 changes: 86 additions & 0 deletions tools/test_relay_api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#!/bin/sh
#
# Copyright (C) 2024 Sébastien Helleu <flashcode@flashtux.org>
#
# This file is part of WeeChat, the extensible chat client.
#
# WeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# WeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WeeChat. If not, see <https://www.gnu.org/licenses/>.
#

#
# Test WeeChat relay HTTP REST API.
#
# Environment variables that can be used:
#
# RELAY_PASSWORD Password for WeeChat relay
#

set -o errexit

# default values for options from environment variables
default_relay_password="test"

usage ()
{
rc=$1
cat <<-EOF
Syntax: $0 url
url URL of the running WeeChat with relay api (without "/api")
Environment variables used:
RELAY_PASSWORD password for the relay (default: "${default_relay_password}")
Example:
RELAY_PASSWORD="test" $0 http://localhost:9000
EOF
exit "${rc}"
}

error_usage ()
{
echo >&2 "ERROR: $*"
usage 1
}

# ================================== START ==================================

# relay password
[ -z "${RELAY_PASSWORD}" ] && RELAY_PASSWORD="${default_relay_password}"

# check command line arguments
if [ $# -eq 0 ]; then
usage 0
fi
if [ $# -lt 1 ]; then
error_usage "missing arguments"
fi

# command line arguments
url="$1"

schemathesis run \
--checks all \
--validate-schema=true \
--experimental=openapi-3.1 \
--base-url "${url}/api" \
--auth "plain:${RELAY_PASSWORD}" \
./src/plugins/relay/api/weechat-relay-api.yaml \
;

exit 0

0 comments on commit 6db01be

Please sign in to comment.