mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-05 02:00:30 -07:00
Add integration tests for 'prettytable' plugin
This commit is contained in:
parent
e4874f7a76
commit
f316fc99e2
9 changed files with 203 additions and 1 deletions
|
@ -119,7 +119,7 @@ EXAMPLES = r'''
|
|||
- name: Bob
|
||||
age: 30
|
||||
role: user
|
||||
column_order:
|
||||
column_order:
|
||||
- name
|
||||
- role
|
||||
- age
|
||||
|
|
1
tests/integration/targets/prettytable/aliases
Normal file
1
tests/integration/targets/prettytable/aliases
Normal file
|
@ -0,0 +1 @@
|
|||
azp/posix/1
|
|
@ -0,0 +1,5 @@
|
|||
+------------+-----------------+--------+
|
||||
| date | description | amount |
|
||||
+------------+-----------------+--------+
|
||||
| 2023-01-01 | Office supplies | 123.45 |
|
||||
+------------+-----------------+--------+
|
|
@ -0,0 +1,6 @@
|
|||
+-------+-----+-------+
|
||||
| name | age | role |
|
||||
+-------+-----+-------+
|
||||
| Alice | 25 | admin |
|
||||
| Bob | 30 | user |
|
||||
+-------+-----+-------+
|
|
@ -0,0 +1,5 @@
|
|||
+-----------+----------+-----------+
|
||||
| User Name | User Age | User Role |
|
||||
+-----------+----------+-----------+
|
||||
| Alice | 25 | admin |
|
||||
+-----------+----------+-----------+
|
|
@ -0,0 +1,2 @@
|
|||
++
|
||||
++
|
|
@ -0,0 +1,6 @@
|
|||
+-------+-------+-----+
|
||||
| role | name | age |
|
||||
+-------+-------+-----+
|
||||
| admin | Alice | 25 |
|
||||
| user | Bob | 30 |
|
||||
+-------+-------+-----+
|
1
tests/integration/targets/prettytable/meta/main.yml
Normal file
1
tests/integration/targets/prettytable/meta/main.yml
Normal file
|
@ -0,0 +1 @@
|
|||
---
|
176
tests/integration/targets/prettytable/tasks/main.yml
Normal file
176
tests/integration/targets/prettytable/tasks/main.yml
Normal file
|
@ -0,0 +1,176 @@
|
|||
---
|
||||
- name: Install required libs
|
||||
pip:
|
||||
name: prettytable
|
||||
state: present
|
||||
delegate_to: localhost
|
||||
become: false
|
||||
|
||||
# Test basic functionality
|
||||
- name: Test basic table creation
|
||||
prettytable:
|
||||
data:
|
||||
- name: Alice
|
||||
age: 25
|
||||
role: admin
|
||||
- name: Bob
|
||||
age: 30
|
||||
role: user
|
||||
register: basic_result
|
||||
|
||||
- name: Load expected basic table output
|
||||
set_fact:
|
||||
expected_basic_table: "{{ lookup('file', 'basic_table.txt') }}"
|
||||
|
||||
- name: Verify basic table output
|
||||
assert:
|
||||
that:
|
||||
- basic_result.pretty_table | trim == expected_basic_table | trim
|
||||
- not basic_result.failed
|
||||
|
||||
# Test column ordering
|
||||
- name: Test table with custom column order
|
||||
prettytable:
|
||||
data:
|
||||
- name: Alice
|
||||
age: 25
|
||||
role: admin
|
||||
- name: Bob
|
||||
age: 30
|
||||
role: user
|
||||
column_order:
|
||||
- role
|
||||
- name
|
||||
- age
|
||||
register: ordered_result
|
||||
|
||||
- name: Load expected ordered table output
|
||||
set_fact:
|
||||
expected_ordered_table: "{{ lookup('file', 'ordered_table.txt') }}"
|
||||
|
||||
- name: Verify ordered table output
|
||||
assert:
|
||||
that:
|
||||
- ordered_result.pretty_table | trim == expected_ordered_table | trim
|
||||
- not ordered_result.failed
|
||||
|
||||
# Test custom headers
|
||||
- name: Test table with custom headers
|
||||
prettytable:
|
||||
data:
|
||||
- name: Alice
|
||||
age: 25
|
||||
role: admin
|
||||
header_names:
|
||||
- "User Name"
|
||||
- "User Age"
|
||||
- "User Role"
|
||||
register: headers_result
|
||||
|
||||
- name: Load expected headers table output
|
||||
set_fact:
|
||||
expected_headers_table: "{{ lookup('file', 'custom_headers.txt') }}"
|
||||
|
||||
- name: Verify custom headers output
|
||||
assert:
|
||||
that:
|
||||
- headers_result.pretty_table | trim == expected_headers_table | trim
|
||||
- not headers_result.failed
|
||||
|
||||
# Test column alignments
|
||||
- name: Test table with alignments
|
||||
prettytable:
|
||||
data:
|
||||
- date: "2023-01-01"
|
||||
description: "Office supplies"
|
||||
amount: 123.45
|
||||
column_alignments:
|
||||
amount: right
|
||||
description: left
|
||||
date: center
|
||||
register: aligned_result
|
||||
|
||||
- name: Load expected aligned table output
|
||||
set_fact:
|
||||
expected_aligned_table: "{{ lookup('file', 'aligned_table.txt') }}"
|
||||
|
||||
- name: Verify aligned table output
|
||||
assert:
|
||||
that:
|
||||
- aligned_result.pretty_table | trim == expected_aligned_table | trim
|
||||
- not aligned_result.failed
|
||||
|
||||
# Test error conditions
|
||||
- name: Test missing data parameter (should fail)
|
||||
prettytable: {} # Empty dict to test missing required parameter
|
||||
register: missing_data_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Verify error for missing data
|
||||
vars:
|
||||
expected_msg: 'missing required arguments: data'
|
||||
assert:
|
||||
that:
|
||||
- missing_data_result.failed
|
||||
- expected_msg in missing_data_result.msg
|
||||
|
||||
- name: Test invalid data type (should fail)
|
||||
prettytable:
|
||||
data: "this is a string"
|
||||
register: invalid_data_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Verify error for invalid data
|
||||
vars:
|
||||
expected_msg: "Expected a list of dictionaries, got a string"
|
||||
assert:
|
||||
that:
|
||||
- invalid_data_result.failed
|
||||
- expected_msg == invalid_data_result.msg
|
||||
|
||||
- name: Test list with invalid items (should fail)
|
||||
prettytable:
|
||||
data:
|
||||
- {"valid": "dict"}
|
||||
- "invalid string item"
|
||||
register: invalid_items_result
|
||||
ignore_errors: true
|
||||
|
||||
- name: Verify error for invalid items
|
||||
vars:
|
||||
expected_msg: "All items in the list must be dictionaries, got a string"
|
||||
assert:
|
||||
that:
|
||||
- invalid_items_result.failed
|
||||
- expected_msg == invalid_items_result.msg
|
||||
|
||||
# Test empty data
|
||||
- name: Test empty data list
|
||||
prettytable:
|
||||
data: []
|
||||
register: empty_result
|
||||
|
||||
- name: Load expected empty table output
|
||||
set_fact:
|
||||
expected_empty_table: "{{ lookup('file', 'empty_table.txt') }}"
|
||||
|
||||
- name: Verify empty table output
|
||||
assert:
|
||||
that:
|
||||
- empty_result.pretty_table | trim == expected_empty_table | trim
|
||||
- not empty_result.failed
|
||||
|
||||
# Test invalid alignments
|
||||
- name: Test invalid alignment value
|
||||
prettytable:
|
||||
data:
|
||||
- col1: value1
|
||||
col2: value2
|
||||
column_alignments:
|
||||
col1: invalid
|
||||
register: invalid_alignment_result
|
||||
|
||||
- name: Verify invalid alignment handling
|
||||
assert:
|
||||
that:
|
||||
- not invalid_alignment_result.failed # Should not fail, just warn
|
Loading…
Add table
Reference in a new issue