Skip to content

Commit d50f97e

Browse files
dploegerDennis Ploeger
authored andcommitted
chore: Optimized runs of test suite
1 parent d0b1351 commit d50f97e

File tree

7 files changed

+75
-63
lines changed

7 files changed

+75
-63
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@ jobs:
2727
run: |
2828
python -m pip install --upgrade pip
2929
pip install -r requirements.txt -r requirements-dev.txt
30-
- name: Run default test
30+
- name: Run testsuite
3131
working-directory: test
32-
run: python -m ansible.cli.playbook playbook.yaml -i default/inventory.yaml -e expected_records=21 -vvv
33-
- name: Run dump configuration test
34-
working-directory: test
35-
env:
36-
LOKI_ENABLED_DUMPS: play
37-
run: python -m ansible.cli.playbook playbook.yaml -i default/inventory.yaml -e expected_records=27 -vvv
32+
run: /usr/bin/env bash test.sh

test/ansible.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[defaults]
2-
callback_plugins=../
3-
41
[loki]
52
url=http://localhost:3100/loki/api/v1/push
63
default_tags=run:test

test/playbook.yaml

Lines changed: 0 additions & 53 deletions
This file was deleted.

test/playbook_check.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
- hosts: 127.0.0.1
2+
gather_facts: false
3+
connection: local
4+
name: "Checking results"
5+
tasks:
6+
- name: "Fetching number of recorded logs"
7+
uri:
8+
url: http://localhost:3100/loki/api/v1/query_range?query={{ '{run="test"}' | urlencode }}
9+
body_format: json
10+
register: logs
11+
- name: tmp1
12+
ansible.builtin.debug:
13+
var: expected_records
14+
- name: tmp2
15+
ansible.builtin.debug:
16+
var: logs.json.data.result | length
17+
- fail:
18+
msg: "Invalid number of records"
19+
when: logs.json.data.result | length != expected_records | int

test/playbook_cleanup.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- hosts: 127.0.0.1
2+
gather_facts: false
3+
connection: local
4+
name: Stop Loki
5+
tasks:
6+
- name: Stop Loki container
7+
docker_container:
8+
name: "ansible-loki-callback-test"
9+
state: stopped

test/playbook_prepare.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
- hosts: 127.0.0.1
2+
gather_facts: false
3+
connection: local
4+
name: Start Loki
5+
tasks:
6+
- name: Start Loki container
7+
docker_container:
8+
image: "grafana/loki:3.0.1"
9+
name: "ansible-loki-callback-test"
10+
auto_remove: true
11+
published_ports:
12+
- "3100:3100"
13+
state: started
14+
register: loki_container
15+
- name: Wait for Loki to be ready
16+
uri:
17+
url: "http://localhost:3100/ready"
18+
register: _result
19+
until: _result.status == 200
20+
retries: 100
21+
delay: 5

test/test.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
function run() {
6+
if ! LOG=$("$@" 2>&1); then
7+
STATUS=$?
8+
echo "$LOG"
9+
exit $STATUS
10+
fi
11+
}
12+
13+
echo "Running default test"
14+
run python -m ansible.cli.playbook playbook_prepare.yaml
15+
ANSIBLE_CALLBACK_PLUGINS=.. run python -m ansible.cli.playbook default/playbook.yaml -i default/inventory.yaml -vvv
16+
run python -m ansible.cli.playbook playbook_check.yaml -e expected_records=20 -vvv
17+
run python -m ansible.cli.playbook playbook_cleanup.yaml
18+
19+
# Check with dumps
20+
echo "Running dump test"
21+
run python -m ansible.cli.playbook playbook_prepare.yaml
22+
LOKI_ENABLED_DUMPS=task ANSIBLE_CALLBACK_PLUGINS=.. run python -m ansible.cli.playbook default/playbook.yaml -i default/inventory.yaml -vvv
23+
run python -m ansible.cli.playbook playbook_check.yaml -e expected_records=26 -vvv
24+
run python -m ansible.cli.playbook playbook_cleanup.yaml

0 commit comments

Comments
 (0)