Skip to content

Commit

Permalink
chore: Optimized runs of test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
dploeger committed Aug 19, 2024
1 parent d0b1351 commit d50f97e
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 63 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt -r requirements-dev.txt
- name: Run default test
- name: Run testsuite
working-directory: test
run: python -m ansible.cli.playbook playbook.yaml -i default/inventory.yaml -e expected_records=21 -vvv
- name: Run dump configuration test
working-directory: test
env:
LOKI_ENABLED_DUMPS: play
run: python -m ansible.cli.playbook playbook.yaml -i default/inventory.yaml -e expected_records=27 -vvv
run: /usr/bin/env bash test.sh
3 changes: 0 additions & 3 deletions test/ansible.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[defaults]
callback_plugins=../

[loki]
url=http://localhost:3100/loki/api/v1/push
default_tags=run:test
53 changes: 0 additions & 53 deletions test/playbook.yaml

This file was deleted.

19 changes: 19 additions & 0 deletions test/playbook_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- hosts: 127.0.0.1
gather_facts: false
connection: local
name: "Checking results"
tasks:
- name: "Fetching number of recorded logs"
uri:
url: http://localhost:3100/loki/api/v1/query_range?query={{ '{run="test"}' | urlencode }}
body_format: json
register: logs
- name: tmp1
ansible.builtin.debug:
var: expected_records
- name: tmp2
ansible.builtin.debug:
var: logs.json.data.result | length
- fail:
msg: "Invalid number of records"
when: logs.json.data.result | length != expected_records | int
9 changes: 9 additions & 0 deletions test/playbook_cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- hosts: 127.0.0.1
gather_facts: false
connection: local
name: Stop Loki
tasks:
- name: Stop Loki container
docker_container:
name: "ansible-loki-callback-test"
state: stopped
21 changes: 21 additions & 0 deletions test/playbook_prepare.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
- hosts: 127.0.0.1
gather_facts: false
connection: local
name: Start Loki
tasks:
- name: Start Loki container
docker_container:
image: "grafana/loki:3.0.1"
name: "ansible-loki-callback-test"
auto_remove: true
published_ports:
- "3100:3100"
state: started
register: loki_container
- name: Wait for Loki to be ready
uri:
url: "http://localhost:3100/ready"
register: _result
until: _result.status == 200
retries: 100
delay: 5
24 changes: 24 additions & 0 deletions test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -euo pipefail

function run() {
if ! LOG=$("$@" 2>&1); then
STATUS=$?
echo "$LOG"
exit $STATUS
fi
}

echo "Running default test"
run python -m ansible.cli.playbook playbook_prepare.yaml
ANSIBLE_CALLBACK_PLUGINS=.. run python -m ansible.cli.playbook default/playbook.yaml -i default/inventory.yaml -vvv
run python -m ansible.cli.playbook playbook_check.yaml -e expected_records=20 -vvv
run python -m ansible.cli.playbook playbook_cleanup.yaml

# Check with dumps
echo "Running dump test"
run python -m ansible.cli.playbook playbook_prepare.yaml
LOKI_ENABLED_DUMPS=task ANSIBLE_CALLBACK_PLUGINS=.. run python -m ansible.cli.playbook default/playbook.yaml -i default/inventory.yaml -vvv
run python -m ansible.cli.playbook playbook_check.yaml -e expected_records=26 -vvv
run python -m ansible.cli.playbook playbook_cleanup.yaml

0 comments on commit d50f97e

Please sign in to comment.