Skip to content

Commit 344fd19

Browse files
AlanCodingPeter Braun
authored andcommitted
AAP-37282 Add parse JQ data and test it for a job object in isolation (#15774)
* Add jq dependency * Add file in progress * Add license for jq * Write test and get it passing
1 parent 558cfde commit 344fd19

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
{
3+
"demo.query.example": "{canonical_facts: {host_name: .direct_host_name}, facts: {device_type: .device_type}}"
4+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from awx.main.tasks.host_indirect import build_indirect_host_data
2+
from awx.main.models import Job
3+
4+
5+
def test_indirect_host_counting(live_tmp_folder, run_job_from_playbook):
6+
run_job_from_playbook('test_indirect_host_counting', 'run_task.yml', scm_url=f'file://{live_tmp_folder}/test_host_query')
7+
job = Job.objects.filter(name__icontains='test_indirect_host_counting').order_by('-created').first()
8+
9+
# Data matches to awx/main/tests/data/projects/host_query/meta/event_query.yml
10+
# this just does things in-line to be a more localized test for the immediate testing
11+
event_query = {'demo.query.example': '{canonical_facts: {host_name: .direct_host_name}, facts: {device_type: .device_type}}'}
12+
13+
# Run the task logic directly with local data
14+
results = build_indirect_host_data(job, event_query)
15+
assert len(results) == 1
16+
host_audit_entry = results[0]
17+
18+
# Asserts on data that will match to the input jq string from above
19+
assert host_audit_entry.canonical_facts == {'host_name': 'foo_host_default'}
20+
assert host_audit_entry.facts == {'device_type': 'Fake Host'}

0 commit comments

Comments
 (0)