Skip to content

Commit

Permalink
test: add basic integration test for each module
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasheld committed Jan 10, 2023
1 parent c8075be commit def0f60
Show file tree
Hide file tree
Showing 20 changed files with 148 additions and 11 deletions.
4 changes: 2 additions & 2 deletions plugins/modules/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
api_password: secret123
type: keyword
name: Monitor 1
url: http://192.168.20.135
url: http://127.0.0.1
keyword: healthy
state: present
Expand All @@ -233,7 +233,7 @@
api_password: secret123
type: http
name: Monitor 1
url: http://192.168.20.135
url: http://127.0.0.1
state: present
- name: Remove a monitor
Expand Down
36 changes: 27 additions & 9 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
#!/bin/sh

# usage:
#
# run all tests:
# ./run_tests.sh
#
# run all tests against specific uptime kuma version:
# ./run_tests.sh 1.19.4
#
# run all tests against specific uptime kuma version and specific modules:
# ./run_tests.sh 1.19.4 maintenance maintenance_info

collection_path="$HOME/.ansible/collections/ansible_collections/lucasheld/uptime_kuma"
version="$1"
files="${@:2}"
modules="${@:2}"

if [ ! -d "$collection_path" ]
then
Expand All @@ -15,14 +26,17 @@ if [ $version ] && [ "$version" != "all" ]
then
versions=("$version")
else
versions=(1.19.3 1.18.5 1.17.1)
versions=(1.19.4 1.18.5 1.17.1)
fi

targets=""
for file in ${files[*]}
unit_targets=""
integration_targets=""
for module in ${modules[*]}
do
filepath="tests/unit/plugins/module_utils/${file}"
targets+="$filepath "
unit_filepath="tests/unit/plugins/module_utils/test_${module}.py"
unit_targets+="${unit_filepath} "

integration_targets+="${module} "
done

for version in ${versions[*]}
Expand All @@ -37,11 +51,15 @@ do
sleep 0.5
done

echo "Running tests..."
ansible-test units -v --target-python default --num-workers 1 $targets
echo "Running unit tests..."
ansible-test units -v --target-python default --num-workers 1 $unit_targets

echo ""
echo "Running integration tests..."
ansible-test integration -v $integration_targets

echo "Stopping uptime kuma..."
docker stop uptimekuma > /dev/null

echo ''
echo ""
done
8 changes: 8 additions & 0 deletions tests/integration/targets/docker_host/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Add docker host
lucasheld.uptime_kuma.docker_host:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
name: Docker host 1
dockerType: socket
dockerDaemon: /var/run/docker.sock
5 changes: 5 additions & 0 deletions tests/integration/targets/docker_host_info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: get all docker hosts
lucasheld.uptime_kuma.docker_host_info:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
5 changes: 5 additions & 0 deletions tests/integration/targets/login/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: login
lucasheld.uptime_kuma.login:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
8 changes: 8 additions & 0 deletions tests/integration/targets/maintenance/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Add a maintenance
lucasheld.uptime_kuma.maintenance:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
title: maintenance 1
strategy: single
state: present
5 changes: 5 additions & 0 deletions tests/integration/targets/maintenance_info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: get all maintenances
lucasheld.uptime_kuma.maintenance_info:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
10 changes: 10 additions & 0 deletions tests/integration/targets/monitor/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- name: Add a monitor
lucasheld.uptime_kuma.monitor:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
type: keyword
name: Monitor 1
url: http://127.0.0.1
keyword: healthy
state: present
5 changes: 5 additions & 0 deletions tests/integration/targets/monitor_info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: get all monitors
lucasheld.uptime_kuma.monitor_info:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
12 changes: 12 additions & 0 deletions tests/integration/targets/notification/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- name: Add notification
lucasheld.uptime_kuma.notification:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
name: Notification 1
type: telegram
isDefault: false
applyExisting: false
telegramBotToken: 1111
telegramChatID: 2222
state: present
5 changes: 5 additions & 0 deletions tests/integration/targets/notification_info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: get all notifications
lucasheld.uptime_kuma.notification_info:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
9 changes: 9 additions & 0 deletions tests/integration/targets/proxy/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- name: Add proxy
lucasheld.uptime_kuma.proxy:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
protocol: http
host: 127.0.0.1
port: 8080
state: present
5 changes: 5 additions & 0 deletions tests/integration/targets/proxy_info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: get all proxies
lucasheld.uptime_kuma.proxy_info:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
6 changes: 6 additions & 0 deletions tests/integration/targets/settings/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- name: Enable beta version update check
lucasheld.uptime_kuma.settings:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
checkBeta: true
5 changes: 5 additions & 0 deletions tests/integration/targets/settings_info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: get settings
lucasheld.uptime_kuma.settings_info:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
5 changes: 5 additions & 0 deletions tests/integration/targets/setup/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: Setup
lucasheld.uptime_kuma.setup:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
8 changes: 8 additions & 0 deletions tests/integration/targets/status_page/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Add status page
lucasheld.uptime_kuma.status_page:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
slug: testslug
title: testtitle
state: present
5 changes: 5 additions & 0 deletions tests/integration/targets/status_page_info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: get all status_pages
lucasheld.uptime_kuma.status_page_info:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
8 changes: 8 additions & 0 deletions tests/integration/targets/tag/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- name: Add tag
lucasheld.uptime_kuma.tag:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123
name: Tag 1
color: "#ff0000"
state: present
5 changes: 5 additions & 0 deletions tests/integration/targets/tag_info/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: get all tags
lucasheld.uptime_kuma.tag_info:
api_url: http://127.0.0.1:3001
api_username: admin
api_password: secret123

0 comments on commit def0f60

Please sign in to comment.