[test coverage] Add tests for set_stats (#74243)
* satisfy the all-knowing, ever present God of Sanity and use 'grep -c' vs. 'wc -l'
This commit is contained in:
parent
93fdba7013
commit
5e55af2f02
4 changed files with 106 additions and 0 deletions
1
test/integration/targets/set_stats/aliases
Normal file
1
test/integration/targets/set_stats/aliases
Normal file
|
@ -0,0 +1 @@
|
||||||
|
shippable/posix/group5
|
13
test/integration/targets/set_stats/runme.sh
Executable file
13
test/integration/targets/set_stats/runme.sh
Executable file
|
@ -0,0 +1,13 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
export ANSIBLE_SHOW_CUSTOM_STATS=yes
|
||||||
|
|
||||||
|
# Simple tests
|
||||||
|
ansible-playbook test_simple.yml
|
||||||
|
|
||||||
|
# This playbook does two set_stats calls setting my_int to 10 and 15.
|
||||||
|
# The aggregated output should add to 25.
|
||||||
|
output=$(ansible-playbook test_aggregate.yml | grep -c '"my_int": 25')
|
||||||
|
test "$output" -eq 1
|
13
test/integration/targets/set_stats/test_aggregate.yml
Normal file
13
test/integration/targets/set_stats/test_aggregate.yml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: First set_stats
|
||||||
|
set_stats:
|
||||||
|
data:
|
||||||
|
my_int: 10
|
||||||
|
|
||||||
|
- name: Second set_stats
|
||||||
|
set_stats:
|
||||||
|
data:
|
||||||
|
my_int: 15
|
79
test/integration/targets/set_stats/test_simple.yml
Normal file
79
test/integration/targets/set_stats/test_simple.yml
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
---
|
||||||
|
- hosts: localhost
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: test simple data with defaults
|
||||||
|
set_stats:
|
||||||
|
data:
|
||||||
|
my_int: 42
|
||||||
|
my_string: "foo"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert simple data return
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is succeeded
|
||||||
|
- not result.changed
|
||||||
|
- '"ansible_stats" in result'
|
||||||
|
- '"data" in result.ansible_stats'
|
||||||
|
- result.ansible_stats.data.my_int == 42
|
||||||
|
- result.ansible_stats.data.my_string == "foo"
|
||||||
|
- '"per_host" in result.ansible_stats'
|
||||||
|
- not result.ansible_stats.per_host
|
||||||
|
- '"aggregate" in result.ansible_stats'
|
||||||
|
- result.ansible_stats.aggregate
|
||||||
|
|
||||||
|
- name: test per_host and aggregate settings
|
||||||
|
set_stats:
|
||||||
|
data:
|
||||||
|
my_int: 42
|
||||||
|
per_host: yes
|
||||||
|
aggregate: no
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert per_host and aggregate changes
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is succeeded
|
||||||
|
- not result.changed
|
||||||
|
- '"ansible_stats" in result'
|
||||||
|
- '"per_host" in result.ansible_stats'
|
||||||
|
- result.ansible_stats.per_host
|
||||||
|
- '"aggregate" in result.ansible_stats'
|
||||||
|
- not result.ansible_stats.aggregate
|
||||||
|
|
||||||
|
- name: Test bad call
|
||||||
|
block:
|
||||||
|
- name: "EXPECTED FAILURE - test invalid data type"
|
||||||
|
set_stats:
|
||||||
|
data:
|
||||||
|
- 1
|
||||||
|
- 2
|
||||||
|
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - test invalid data type"
|
||||||
|
- ansible_failed_result.msg == "The 'data' option needs to be a dictionary/hash"
|
||||||
|
|
||||||
|
- name: Test options from template
|
||||||
|
set_stats:
|
||||||
|
data:
|
||||||
|
my_string: "foo"
|
||||||
|
aggregate: "x"
|
||||||
|
|
||||||
|
- name: Test bad data
|
||||||
|
block:
|
||||||
|
- name: "EXPECTED FAILURE - bad data"
|
||||||
|
set_stats:
|
||||||
|
data:
|
||||||
|
.bad: 1
|
||||||
|
- fail:
|
||||||
|
msg: "should not get here"
|
||||||
|
rescue:
|
||||||
|
- assert:
|
||||||
|
that:
|
||||||
|
- ansible_failed_task.name == "EXPECTED FAILURE - bad data"
|
||||||
|
- ansible_failed_result.msg == "The variable name '.bad' is not valid. Variables must start with a letter or underscore character, and contain only letters, numbers and underscores."
|
Loading…
Reference in a new issue